001: /*
002: * LICENSE INFORMATION
003: * Copyright 2005-2007 by FZI (http://www.fzi.de).
004: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
005: * <OWNER> = Max Völkel
006: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
007: * <YEAR> = 2007
008: *
009: * Project information at http://semweb4j.org/rdf2go
010: */
011: package org.ontoware.rdf2go.model;
012:
013: import org.ontoware.aifbcommons.collection.ClosableIterator;
014: import org.ontoware.rdf2go.exception.ModelRuntimeException;
015: import org.ontoware.rdf2go.model.node.Node;
016: import org.ontoware.rdf2go.model.node.Resource;
017: import org.ontoware.rdf2go.model.node.URI;
018:
019: /**
020: * A ModelSet is like a Graph Data Set in SPARQL. It contains a number of named
021: * graphs (Models), which might be empty. Additionally, one special unnamed
022: * model, the 'Default Model' belongs to a ModelSet.
023: *
024: * ModelSet offers a number of methods that make it behave like a quad store,
025: * however, when e.g. removing all statements with a certain context, the model
026: * named with that context still remains in the ModelSet.
027: *
028: * <p>
029: * <code>ModelSet</code> can be read from a named graph aware serialization
030: * such as TRIG or TRIX using the read/write methods. If you read a
031: * serialization that supports only one graph (like RDF/XML), a default model
032: * will be created.
033: * </p>
034: *
035: * The context URI of the default modell is 'null'.
036: *
037: * @author max
038: * @author sauermann
039: */
040: public interface ModelSet extends Sparqlable, ModelSetIO,
041: FindableModelSet, ModelSetAddRemove, ModelValueFactory,
042: Commitable, ReificationSupport {
043:
044: /**
045: * Open connection to defined, unterlying implementation
046: */
047: void open();
048:
049: /**
050: * @return true if ModelSet is open
051: */
052: boolean isOpen();
053:
054: /**
055: * Close connection to defined, unterlying implementation
056: */
057: void close();
058:
059: /**
060: * The number of explicit statements. Statements that are inferred e.g.
061: * using backward-chaining are per definition not in this number, and also
062: * some inferred stateemtns may or may be not part of ths size, depending on
063: * the implementation of the model. If a new triple is added to the model,
064: * the size must increase.
065: *
066: * @return the number of statements in the modelset.
067: * @throws ModelRuntimeException
068: */
069: long size() throws ModelRuntimeException;
070:
071: /**
072: * @return true if all models in this ModelSet contain zero statements. This
073: * method might be faster than calling size() == 0 on each model.
074: * Note: This method can return isEmpty == true, even if the
075: * ModelSet contains a number of models.
076: */
077: boolean isEmpty();
078:
079: /**
080: * Creates an RDF2Go URI. This allows a user to create a model via
081: * 'getModel( URI )'.
082: *
083: * @param uriString
084: * @return an RDF2Go URI
085: * @throws ModelRuntimeException
086: * if URI has not a valid URI fomat - according to the adapter
087: */
088: URI createURI(String uriString) throws ModelRuntimeException;
089:
090: /**
091: * Creates a statement with a context URI.
092: *
093: * @param context
094: * @param subject
095: * @param predicate
096: * @param object
097: * @return
098: */
099: Statement createStatement(URI context, Resource subject,
100: URI predicate, Node object);
101:
102: /**
103: * Get the Model with the passed URI. If the model does not exist yet, an
104: * empty model will be created and returned.
105: *
106: * Note that the returned model is tied to this modelset, and any changes in
107: * the model will be reflected here.
108: *
109: * @param contextURI
110: * the URI of the context. This is the same as the name of the
111: * named graph.
112: * @return the model identified by this context. May have a size of 0, if no
113: * data was added to it yet. Never returns null. It has to be isOpen() == true.
114: */
115: Model getModel(URI contextURI);
116:
117: /**
118: * Removes the Model (NamedGraph) denoted by contextURI from this modelset.
119: * If the model contains statements, they are deleted.
120: *
121: * @param contextURI
122: * @return true if successful
123: */
124: boolean removeModel(URI contextURI);
125:
126: /**
127: * Adds a model to this ModelSet. Creating the named-graph if needed, adding
128: * the triples to it if not.
129: *
130: * This method might be much quicker than addAll(model.iterator()) depending
131: * on the implementation.
132: *
133: * @param model
134: * @return true if successful
135: */
136: boolean addModel(Model model);
137:
138: /**
139: * @param contextURI
140: * @return true if a Model (NamedGraph) named 'contextURI' is known. The
141: * model might be empty. Some implementations don't manage models
142: * explicitly, here empty models cna never exist.
143: */
144: boolean containsModel(URI contextURI);
145:
146: /**
147: * Removes all models, which is
148: * <em>not</emp> the same as removing all statements from all
149: * models in this ModelSet.
150: *
151: * @throws ModelRuntimeException
152: */
153: void removeAll() throws ModelRuntimeException;
154:
155: /**
156: * The default model is used when the modelset is loaded from a
157: * serialization that has no context. The default model has a context of
158: * 'null'
159: *
160: * @return the default model. It has to be isOpen() == true.
161: */
162: Model getDefaultModel();
163:
164: /**
165: * @return an Interator over <em>all</em> models within this ModelSet.
166: * Some models might be empty.
167: *
168: * Since 4.4.10: Each model has to be isOpen() == true.
169: *
170: * For some implementations: While you read the iterator you may not WRITE
171: * to the models.
172: *
173: */
174: ClosableIterator<Model> getModels();
175:
176: /**
177: * @return an iterator over all URIs used as model URIs.
178: *
179: * For some implementations: While you read the iterator you may not WRITE
180: * to the models.
181: */
182: ClosableIterator<URI> getModelURIs();
183:
184: /**
185: * @return the native implementation (e.g. a Jena Model). Using this method
186: * breaks strict triple store independence, but exposes the full
187: * power and <b>reduces</b> API dependence. This method is part of
188: * the main API.
189: */
190: Object getUnderlyingModelSetImplementation();
191:
192: /**
193: * Print the whole content of this ModelSet to System.out.
194: */
195: void dump();
196:
197: }
|