我正在实现一个从WebProtege中使用的OWLEntity的URI中提取实体的版本。我很成功。我可以告诉你下面的代码。但我现在要求从标签注释中提取。如何使用WebProtege提取它。创建类时,WebProtege不会创建URI(例如,http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#Pizza)。它只有URI标签注释。我想从标签中提取URI。因为它(例如,http://www.co-ode.org/ontologies/pizza/2005/05/16/234y2890820802840>“披萨”@ en>。(看起来有点像。如果你需要正确的话,我会回复。)。
rootOntology = getProject().getRootOntology();
System.out.println(rootOntology.getAxioms());
final OWLDataFactory dataFactory
= rootOntology.getOWLOntologyManager().getOWLDataFactory();
iriShortFormProvider = new SimpleIRIShortFormProvider();
ShortFormProvider shortFormProvider = new ShortFormProvider() {
public String getShortForm(OWLEntity owlEntity) {
return iriShortFormProvider.getShortForm(owlEntity.getIRI());
}
@Override
public void dispose() {
}
};
OWLEntityChecker entityChecker
= new ShortFormEntityChecker(
new BidirectionalShortFormProviderAdapter(
Collections.singleton(rootOntology), shortFormProvider));
ManchesterOWLSyntaxEditorParser parser
= new ManchesterOWLSyntaxEditorParser(
dataFactory, query);
parser.setOWLEntityChecker(entityChecker);
Set<OntologyAxiomPair> set;
try {
set = parser.parseFrames();
System.out.println("SET SIZE" + set.size());
System.out.println("SET STRING" + set.toString());
for (OntologyAxiomPair s1 : set) {
OWLAxiom temp = s1.getAxiom();
Set<OWLAnnotationProperty> annotation = s1.getOntology().getAnnotationPropertiesInSignature();
Iterator itr = annotation.iterator();
while(itr.hasNext()){
System.out.println(s1.getOntology().getAnnotationPropertiesInSignature());
System.out.println("ITERATOR" + itr.next());
}
if (temp.getAxiomType() != AxiomType.DECLARATION
|| temp.getAxiomType() != AxiomType.SUBCLASS_OF || temp.getAxiomType() != AxiomType.DATA_PROPERTY_ASSERTION
)
res = Search(temp);
}
来自WebProtege的示例:
<!-- http://webprotege.stanford.edu/classes/BfJkwFDiEj5mduXojVHyKi -->
<owl:Class rdf:about="http://webprotege.stanford.edu/classes/BfJkwFDiEj5mduXojVHyKi">
<rdfs:label xml:lang="en">AnimalType</rdfs:label>
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:Class>
<!-- http://webprotege.stanford.edu/classes/BjSxQcpX7bOcVccVf5beN0 -->
<owl:Class rdf:about="http://webprotege.stanford.edu/classes/BjSxQcpX7bOcVccVf5beN0">
<rdfs:label xml:lang="en">Omnivore</rdfs:label>
<rdfs:subClassOf rdf:resource="http://webprotege.stanford.edu/classes/BfJkwFDiEj5mduXojVHyKi"/>
</owl:Class>
<!-- http://webprotege.stanford.edu/classes/CKjBW7KqdcJPRpBtk2T6WE -->
<owl:Class rdf:about="http://webprotege.stanford.edu/classes/CKjBW7KqdcJPRpBtk2T6WE">
<rdfs:label xml:lang="en">Herbivore</rdfs:label>
<rdfs:subClassOf rdf:resource="http://webprotege.stanford.edu/classes/BfJkwFDiEj5mduXojVHyKi"/>
</owl:Class>
<!-- http://webprotege.stanford.edu/classes/COt181AeQ0WewmOoZ0NYYF -->
<owl:Class rdf:about="http://webprotege.stanford.edu/classes/COt181AeQ0WewmOoZ0NYYF">
<rdfs:label xml:lang="en">Fish</rdfs:label>
<rdfs:subClassOf rdf:resource="http://webprotege.stanford.edu/classes/DfGxuPUoLBiOvyBKpUJWvr"/>
</owl:Class>
<!-- http://webprotege.stanford.edu/classes/CPp9DIflV676wmq3onRsJa -->
<owl:Class rdf:about="http://webprotege.stanford.edu/classes/CPp9DIflV676wmq3onRsJa">
<rdfs:label xml:lang="en">Land</rdfs:label>
<rdfs:subClassOf rdf:resource="http://webprotege.stanford.edu/classes/7V0PYXjh6vM9AjTzh9DPwC"/>
</owl:Class>
<!-- http://webprotege.stanford.edu/classes/DfGxuPUoLBiOvyBKpUJWvr -->
<owl:Class rdf:about="http://webprotege.stanford.edu/classes/DfGxuPUoLBiOvyBKpUJWvr">
<rdfs:label xml:lang="en">Animal</rdfs:label>
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:Class>
答案 0 :(得分:0)
这就是你获得标签的方式。尽管URI是优选的,但标签也是可行的。您可以将这些标签提供给曼彻斯特语法查询。我建议重写你的查询。
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File file= new File("root-ontology.owl");
OWLOntology rootOntology = manager.loadOntologyFromOntologyDocument(file);
OWLDataFactory df = rootOntology.getOWLOntologyManager().getOWLDataFactory();
Set<OWLLogicalAxiom> LogicalAxiom=rootOntology.getLogicalAxioms();
Iterator<OWLLogicalAxiom> axiom=LogicalAxiom.iterator();
for (OWLClass cls : rootOntology.getClassesInSignature()) {
// Get the annotations on the class that use the label property
for (OWLAnnotation annotation : cls
.getAnnotations(rootOntology, df.getRDFSLabel())) {
if (annotation.getValue() instanceof OWLLiteral) {
OWLLiteral val = (OWLLiteral) annotation.getValue();
// look for portuguese labels
if (val.hasLang("en"))
System.out.println( val.getLiteral());
}
}
}