我使用本体,具有以下"标题":
@prefix : <http://purl.obolibrary.org/obo/doid.owl#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix doid: <http://purl.obolibrary.org/obo/doid#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix fn: <http://www.w3.org/2005/xpath-functions#> .
@prefix sesame: <http://www.openrdf.org/schema/sesame#> .
obo:doid.owl a owl:Ontology ;
oboInOwl:hasOBOFormatVersion "1.2"^^xsd:string ;
oboInOwl:date "25:03:2016 16:27"^^xsd:string ;
oboInOwl:auto-generated-by "OBO-Edit 2.3.1"^^xsd:string ;
rdfs:comment "This work is licensed under a Creative Commons Attribution 3.0 Unported License http://creativecommons.org/licenses/by/3.0/."^^xsd:string ;
oboInOwl:default-namespace "disease_ontology"^^xsd:string ;
oboInOwl:saved-by "someone"^^xsd:string ;
owl:versionIRI <http://purl.obolibrary.org/obo/doid/releases/2016-03-25/doid.owl> .
我将它与另一个本体论合并。合并文件具有以下标题:
@prefix : <file:/Users/Downloads/merged.ttl#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <file:/Users/Downloads/merged.ttl> .
<file:/Users/Downloads/merged.ttl> rdf:type owl:Ontology .
那就是它。我想补充一些属性,比如oboInOwl:hasOBOFormatVersion,rdfs:comment,oboInOwl:default-namespace,oboInOwl:saved-by等。 我怎样才能做到这一点?谢谢。
这是合并代码:
OWLOntology ontology2 = CalcDiff.getOntology2();
File output2 = new File("/ontology_management/DOID_MERGED/doid_do.ttl");
IRI mergedOntologyIRI = IRI.create(output2);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology1 = manager.loadOntologyFromOntologyDocument(new
File("/ontology_management/DOID_CURRENT/doid.ttl"));
OWLDocumentFormat format = manager.getOntologyFormat(ontology1);
// save the merged ontology in Turtle format
TurtleDocumentFormat newFormat = new TurtleDocumentFormat();
// will copy the prefixes over so that we have nicely abbreviated IRIs
// in the new ontology document
if (format.isPrefixOWLOntologyFormat()) {
newFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
}
//Using HashSet to avoid duplicated entries
Set<OWLAxiom> axiomsall = new HashSet<OWLAxiom>();
Set<OWLImportsDeclaration> importsall = new HashSet<OWLImportsDeclaration>();
try {
ontology1.getAxioms().forEach(c -> {axiomsall.add(c);});
ontology1.getImportsDeclarations().forEach(c -> {importsall.add(c);});
ontology2.getAxioms().forEach(c -> {axiomsall.add(c);});
ontology2.getImportsDeclarations().forEach(c -> {importsall.add(c);});
mergedOntology = manager.createOntology(mergedOntologyIRI);
manager.addAxioms(mergedOntology, axiomsall);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
//Adding the import declarations
for(OWLImportsDeclaration decl : importsall){
manager.applyChange(new AddImport(mergedOntology, decl));
}
好的,上面的代码让我达到了这一点:
@prefix : <http://purl.obolibrary.org/obo/doid.owl#> .
@prefix fn: <http://www.w3.org/2005/xpath-functions#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix doid: <http://purl.obolibrary.org/obo/doid#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sesame: <http://www.openrdf.org/schema/sesame#> .
@prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#> .
@base <file:/ontology_management/DOID_MERGED/doid_do.ttl> .
<file:/ontology_management/DOID_MERGED/doid_do.ttl> rdf:type owl:Ontology .
所以现在我有了所有前缀,但Ontology的属性不存在(这是我最感兴趣的)
答案 0 :(得分:4)
你的意思不是称为“属性”而是前缀声明。下一次,提供一些代码如何加载/保存本体是很好的:
OWLOntologyFormat format = manager.getOntologyFormat(YOUR_FIRST_ONTOLOGY);
// save the merged ontology in RDF/XML format
RDFXMLDocumentFormat newFormat = new RDFXMLDocumentFormat();
// will copy the prefixes over so that we have nicely abbreviated IRIs
// in the new ontology document
if (format.isPrefixOWLOntologyFormat()) {
newFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
}
manager.saveOntology(YOUR_MERGED_ONTOLOGY, newFormat, IRI.create(file.toURI()));
复制本体注释:
manager.applyChanges(
ontology1.getAnnotations().stream()
.map(an -> new AddOntologyAnnotation(mergedOntology, an))
.collect(Collectors.toList()));
关于本体的合并,使用现有方法要容易得多:
Set<OWLOntology> ontologies = ...
OWLOntology mergedOntology = manager.createOntology(mergedOntologyIRI, ontologies, false);
或只使用课程org.semanticweb.owlapi.util.OWLOntologyMerger
...