Java源码示例:com.hp.hpl.jena.ontology.OntModelSpec
示例1
private void load(URL ontologyURL){
try {
model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM);
//String file="file:///"+System.getProperty("user.dir")+"/ont/lexicon.owl";
String file=ontologyURL.toExternalForm();
model.read(file,"RDF/XML");
} catch (Exception e) {
logger.warning("Ontology could not be loaded");
e.printStackTrace();
}
}
示例2
public static OntModel loadOntology(InputStream is) {
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_LITE_MEM);
m.read(is, null);
return m;
}
示例3
static void readOwlFile (String pathToOwlFile) {
OntModel ontologyModel =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
ontologyModel.read(pathToOwlFile, "RDF/XML-ABBREV");
// OntClass myClass = ontologyModel.getOntClass("namespace+className");
OntClass myClass = ontologyModel.getOntClass(ResourcesUri.nwr+"domain-ontology#Motion");
System.out.println("myClass.toString() = " + myClass.toString());
System.out.println("myClass.getSuperClass().toString() = " + myClass.getSuperClass().toString());
//List list =
// namedHierarchyRoots(ontologyModel);
Iterator i = ontologyModel.listHierarchyRootClasses()
.filterDrop( new Filter() {
public boolean accept( Object o ) {
return ((Resource) o).isAnon();
}} ); ///get all top nodes and excludes anonymous classes
// Iterator i = ontologyModel.listHierarchyRootClasses();
while (i.hasNext()) {
System.out.println(i.next().toString());
/* OntClass ontClass = ontologyModel.getOntClass(i.next().toString());
if (ontClass.hasSubClass()) {
}*/
}
String q = createSparql("event", "<http://www.newsreader-project.eu/domain-ontology#Motion>");
System.out.println("q = " + q);
QueryExecution qe = QueryExecutionFactory.create(q,
ontologyModel);
for (ResultSet rs = qe.execSelect() ; rs.hasNext() ; ) {
QuerySolution binding = rs.nextSolution();
System.out.println("binding = " + binding.toString());
System.out.println("Event: " + binding.get("event"));
}
ontologyModel.close();
}
示例4
/**
* <p>
* Answer a new ontology model which will process in-memory models of
* ontologies expressed the default ontology language (OWL).
* The default document manager
* will be used to load the ontology's included documents.
* </p>
*
* @param spec An ontology model specification that defines the language and reasoner to use
* @param maker A model maker that is used to get the initial store for the ontology (unless
* the base model is given),
* and create addtional stores for the models in the imports closure
* @param base The base model, which contains the contents of the ontology to be processed
* @return A new ontology model
* @see OntModelSpec
*/
public static OntModel createOntologyModel( OntModelSpec spec, ModelMaker maker, Model base ) {
OntModelSpec _spec = new OntModelSpec( spec );
_spec.setImportModelMaker( maker );
return createOntologyModel( _spec, base );
}
示例5
/**
* <p>
* Answer a new ontology model which will process in-memory models of
* ontologies in the given language.
* The default document manager
* will be used to load the ontology's included documents.
* </p>
*
* @param languageURI The URI specifying the ontology language we want to process
* @return A new ontology model
* @see OntModelSpec#getDefaultSpec
*/
public static OntModel createOntologyModel( String languageURI ) {
return createOntologyModel( OntModelSpec.getDefaultSpec( languageURI ), null );
}
示例6
/**
* <p>
* Answer a new ontology model, constructed according to the given ontology model specification,
* and starting with the ontology data in the given model.
* </p>
*
* @param spec An ontology model specification object, that will be used to construct the ontology
* model with different options of ontology language, reasoner, document manager and storage model
* @param base An existing model to treat as an ontology model, or null.
* @return A new ontology model
* @see OntModelSpec
*/
public static OntModel createOntologyModel( OntModelSpec spec, Model base ) {
return new OntModelImpl( spec, base );
}
示例7
/**
* Answer a new ontology model constructed according to the specification, which includes
* a ModelMaker which will create the necessary base model.
*/
public static OntModel createOntologyModel( OntModelSpec spec )
{ return new OntModelImpl( spec ); }
示例8
/**
* Constructs a new MapParser from a Jena model containing the RDF statements
* from a D2RQ mapping file.
* @param mapModel a Jena model containing the RDF statements from a D2RQ mapping file
* @param baseURI used for relative URI patterns
*/
public D2RQReader(Model mapModel, String baseURI) {
this.model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, mapModel);
this.baseURI = absolutizeURI(baseURI);
}