本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel類的典型用法代碼示例。如果您正苦於以下問題:Java OntModel類的具體用法?Java OntModel怎麽用?Java OntModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OntModel類屬於com.hp.hpl.jena.ontology包,在下文中一共展示了OntModel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: triplifyChildNodes
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
private void triplifyChildNodes(OntModel modelAbox, Individual ind, NodeList nlist) {
// Elements order may be relevant. Keep track of index within same tag name group
String currentTagName = "";
int elemTagIndex = 0;
for (int j = 0; nlist != null && j < nlist.getLength(); j++) {
Node node = nlist.item(j);
if (node.getNodeType() != Node.ELEMENT_NODE)
continue;
Element elem = (Element) nlist.item(j);
if (elem.getNodeName().equals(currentTagName)) {
elemTagIndex++;
} else {
elemTagIndex = 0;
currentTagName = elem.getNodeName();
}
triplifyElement(elem, elemTagIndex, ind, modelAbox);
}
}
示例2: loadDefaultModel
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
public static OntModel loadDefaultModel(){
InputStream in = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("Duplex_A_20110505.ttl");
Model model=ModelFactory.createDefaultModel();
model.read(in,null,"TTL");
InputStream ins = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("IFC2X3_TC1.ttl");
InputStream input = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("Duplex_A_20110505_geometry.ttl");
Model geometryModel=ModelFactory.createDefaultModel();
geometryModel.read(input,null,"TTL");
Model schema=ModelFactory.createDefaultModel();
schema.read(ins,null,"TTL");
try {
BimSPARQL.init(model,geometryModel);
} catch (ClassNotFoundException | IOException | ParserConfigurationException | SAXException
| URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OntModel ontology=ModelFactory.createOntologyModel();
ontology.add(schema);
ontology.add(model);
ontology.add(geometryModel);
return ontology;
}
示例3: main
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
public static void main(String[] args) {
OntoManager om = OntoManager.getInstance();
om.load();
OntModel model = om.getModel();
final String NS = om.getOntologyIRI() + "#";
logger.info(NS);
Scanner s = new Scanner(System.in);
while (true) {
System.out.println("enter:");
String clsName = s.nextLine();
System.out.println("enhancing for: |"+clsName+"|");
if(clsName.equalsIgnoreCase("exit"))break;
OntClass pCls = model.getOntClass(NS + clsName);
if(pCls==null){
System.err.println("class does not exist");
continue;
}
LinguisticEnhancer le = new LinguisticEnhancer();
List<SynSuggestion> suggestions = le.suggestLinguisticData(pCls);
// exclude name + labels , syn includes etc when adding syn includes
//for suspects
for (SynSuggestion sug : suggestions) {
logger.debug(sug.toString());
if (true) {
List<String> excludeList = le.getAllExcludes(pCls, le.getClassLabels(pCls).toArray(new String[0]));
le.addSuggestion(pCls, sug, excludeList);
}
}
om.save();
}
}
示例4: readOwlFile
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
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();
}
示例5: testSomeMethod2
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
@Test
public void testSomeMethod2() throws Exception {
Dataset ds = TDBFactory.createDataset("/scratch/WORK2/jena/dataset2/");
OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym1"));
OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym2"));
OntClass thing = model1.createClass("http://www.w3.org/2002/07/owl#Thing");
model1.createIndividual("http://example.com/onto1#VijayRaj", thing);
model2.createIndividual("http://example.;cegilovcom/onto2#VijayRaj", thing);
Model m = model1.union(model2);
FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/mergetestds.xml");
RDFDataMgr.write(fw, ds, RDFFormat.NQUADS_UTF8);
}
示例6: calcSim
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
private void calcSim() {
OntologyIndex.get().load(OntologyIndex.class.getResource(Config.getAppProperty(Config.Key.ONTOLOGY_FILE)));
OntologyIndex oi = OntologyIndex.get();
OntModel model = oi.getModel();
persistenceStore.beginTransaction();
Query query = persistenceStore.createHQLQuery("from Concept");
List<Concept> concepts1 = (List<Concept>)query.list();
Query query1 = persistenceStore.createHQLQuery("from Concept");
List<Concept> concepts2 = (List<Concept>)query1.list();
persistenceStore.endTransaction();
for (Concept co1 : concepts1) {
OntClass c1 = model.getOntClass(co1.getUri());
for (Concept co2 : concepts2) {
OntClass c2 = model.getOntClass(co2.getUri());
}
}
}
示例7: writeUserEntries
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
/**
* Writes the user entities to rdf
*/
private static OntModel writeUserEntries() {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
try {
thewebsemantic.Bean2RDF writer = new Bean2RDF(model);
InitialContext ic = new InitialContext();
UserService userService = (UserService) ic.lookup("java:module/UserService");
List<User> users = userService.getAll();
for (User u : users) {
writer.save(u);
}
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
示例8: writeProjectEntries
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
/**
* Writes the project entities to rdf
*/
private static OntModel writeProjectEntries() {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
try {
thewebsemantic.Bean2RDF writer = new Bean2RDF(model);
InitialContext ic = new InitialContext();
TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
List<Project> projects = treeNodeService.getAllProjects();
for (Project proj : projects) {
writer.save(proj);
}
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
示例9: readSemanticModelFiles
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
/**
* Read the RDF model from files.
*/
public static void readSemanticModelFiles() {
logger.debug("Reading the model from a file");
// Read the model to an existing model
String dataDir = UQasarUtil.getDataDirPath();
String modelPath = "file:///" + dataDir + ONTOLOGYFILE;
// String modelPath = "file:///C:/nyrhinen/Programme/jboss-as-7.1.1.Final/standalone/data/uq-ontology-model.rdf";
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
RDFDataMgr.read(model, modelPath);
// Test output to standard output
// RDFDataMgr.write(System.out, uqModel, RDFFormat.RDFXML_PRETTY);
logger.debug("Model read from file " +modelPath);
UQasarUtil.setUqModel(model);
System.out.println("Reading done.");
}
示例10: translateAndSaveModel
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
public List<ModelError> translateAndSaveModel(OntModel model, String translationFolder,
String modelName, List<String> orderedImports, String saveFilename) throws TranslationException, IOException, URISyntaxException {
// Jena models have been saved to the OwlModels folder by the ModelManager prior to calling the translator. For Jena
// reasoners, no additional saving of OWL models is need so we can continue on to rule translation and saving.
if (errors != null) {
errors.clear();
}
if (model == null) {
return addError("Cannot save model in file '" + saveFilename + "' as it has no model.");
}
if (modelName == null) {
return addError("Cannot save model in file '" + saveFilename + "' as it has no name.");
}
if (saveRuleFileAfterModelSave) {
String ruleFilename = createDerivedFilename(saveFilename, "rules");
String fullyQualifiedRulesFilename = translationFolder + File.separator + ruleFilename;
translateAndSaveRules(model, null, modelName, fullyQualifiedRulesFilename);
}
saveRuleFileAfterModelSave = false; // reset
return (errors != null && errors.size() > 0) ? errors : null;
}
示例11: loadOntModel
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
@Override
public OntModel loadOntModel(String owlFilename) {
try {
FileInputStream is = new FileInputStream(new File(owlFilename));
return initOntModel(is, getOwlFormatFromFile(owlFilename));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
boolean savePI = ontModel.getDocumentManager().getProcessImports();
ontModel.getDocumentManager().setProcessImports(false);
try {
ontModel.read(owlFilename, getOwlFormatFromFile(owlFilename));
}
finally {
ontModel.getDocumentManager().setProcessImports(savePI);
}
return ontModel;
}
示例12: listSubModelsAndPrefixes
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
private Map<String, String> listSubModelsAndPrefixes(Map<String, String> map, OntModel m, String modelUri) {
Ontology onto = m.getOntology(modelUri);
if (onto != null) {
String prefix = m.getNsURIPrefix(modelUri);
if (prefix == null) {
prefix = getGlobalPrefix(modelUri);
}
if (!map.containsKey(modelUri)) {
map.put(modelUri, prefix);
}
ExtendedIterator<OntResource> importsItr = onto.listImports();
if (importsItr.hasNext()) {
while (importsItr.hasNext()) {
OntResource or = importsItr.next();
logger.debug("Ontology of model '" + modelUri + "' has import '" + or.toString() + "' with prefix '" + prefix + "'");
if (!map.containsKey(or.toString())) {
OntModel submodel = m.getImportedModel(or.getURI());
if (submodel != null) {
map = listSubModelsAndPrefixes(map, submodel, or.getURI());
}
}
}
}
}
return map;
}
示例13: addImport
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
@Override
public boolean addImport(String modelName, String importedModelUri) throws ConfigurationException, IOException, InvalidNameException, URISyntaxException {
try {
String altImportUrl = getConfigurationMgr().getAltUrlFromPublicUri(importedModelUri);
OntModel model = getOntModelForEditing(modelName);
Resource importingOntology = model.getOntology(modelName);
if (importingOntology == null) {
importingOntology = model.createResource(modelName);
}
model.getOntology(modelName).addImport(importingOntology);
model.loadImports();
return true;
} catch (ConfigurationException e) {
throw new ConfigurationException("Model cannot be imported as its location is unknown.", e);
}
}
示例14: main
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
public static void main(String args[])
{
String filename = "example4.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// ** TASK 5.1: Read the ontology from the given file **
// Use the FileManager to find the input file
InputStream in = FileManager.get().open(filename);
if (in == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(in, null);
// ** TASK 5.2: Write the ontology **
model.write(System.out, "RDF/XML-ABBREV");
}
示例15: updatePropertyPartition
import com.hp.hpl.jena.ontology.OntModel; //導入依賴的package包/類
protected void updatePropertyPartition(OntModel partitionModel) {
Query query = QueryFactory.create(propertyPartitionQuery);
QueryExecution qexec = QueryExecutionFactory.create(query,
partitionModel);
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext();) {
QuerySolution soln = results.nextSolution();
OntResource property = soln.getResource("property").as(
OntResource.class);
partitions.addPropertyPartition(property, null);
}
} catch (Exception e) {
Log.debug(Dataset.class,
"Failed to execute to execute propertyPartitionQuery");
} finally {
qexec.close();
}
}