ich eine Ontologie von Word
implementieren möchten, die drei Unterklassen umfasst: Ich versuchte, die Ontologie aus einer Datei zu laden, aber ich kann die Unterklassen einer Word
und alle nicht holen die Instanzen einer angegebenen Unterklasse. Mein Code sieht wie folgt aus:kann nicht die Unterklassen und Instanzen des Wortes Ontologie bekommen
import java.util.Iterator;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
public class Main {
public static OWLOntologyManager create() {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
// PriorityCollection<OWLOntologyIRIMapper> iriMappers = m.getIRIMappers();
// iriMappers.add(new AutoIRIMapper(new File("materializedOntologies"), true));
return m;
}
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
// Get hold of an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// Load an ontology from the Web
IRI iri = IRI.create("http://anywhere");
OWLOntology pizzaOntology = `manager.loadOntologyFromOntologyDocument(iri);`
System.out.println("Loaded ontology: " `enter code here`+ WordOntology);
manager.removeOntology(WordOntology);
File file = new File("word.owl");
OWLDataFactory dataFactory = manager.getOWLDataFactory();
PrefixManager pm = new DefaultPrefixManager(base);
OWLClass Word = dataFactory.getOWLClass(":Word", pm);
OWLNamedIndividual Software = `dataFactory.getOWLNamedIndividual(":Software", pm);`
OWLClassAssertionAxiom classAssertion =
dataFactory.getOWLClassAssertionAxiom(Word, Software);
OWLOntology ontology = manager.createOntology(IRI.create(base));
manager.addAxiom(ontology, classAssertion);
manager.saveOntology(ontology, new SystemOutDocumentTarget());
OWLOntologyManager m = create();
OWLOntology o = m.loadOntologyFromOntologyDocument(iri);
assertNotNull(o);
OWLDataFactory factory = manager.getOWLDataFactory();
for (OWLClass cls : o.getClassesInSignature())
System.out.println(cls);
}
}
Willkommen bei Stack Overflow! Bitte lesen Sie unsere [SO Fragen-Checkliste] (http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist), um Ihnen zu helfen, eine gute Frage zu stellen und somit eine gute Antwort zu erhalten. –