首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OWL API -设置新本体的前缀和本体注释(属性)

OWL API -设置新本体的前缀和本体注释(属性)
EN

Stack Overflow用户
提问于 2018-01-08 10:37:50
回答 1查看 563关注 0票数 0

我使用的是一个本体,它有以下“头”:

代码语言:javascript
运行
复制
@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> .

我正在将它与另一个本体合并。合并后的文件具有以下标题:

代码语言:javascript
运行
复制
@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等。我该怎么做呢?谢谢。

下面是合并代码:

代码语言:javascript
运行
复制
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));
}

好的,上面的代码让我走到了这一步:

代码语言:javascript
运行
复制
@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的属性不在那里(这是我最感兴趣的)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-08 12:21:50

您所指的不是“属性”,而是前缀声明。下一次,最好提供一些如何加载/保存本体的代码:

代码语言:javascript
运行
复制
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()));

复制本体注释:

代码语言:javascript
运行
复制
manager.applyChanges(
                    ontology1.getAnnotations().stream()
                            .map(an -> new AddOntologyAnnotation(mergedOntology, an))
                            .collect(Collectors.toList()));

关于本体的合并,使用现有的方法要容易得多:

代码语言:javascript
运行
复制
Set<OWLOntology> ontologies = ...

OWLOntology mergedOntology = manager.createOntology(mergedOntologyIRI, ontologies, false);

或者只使用类org.semanticweb.owlapi.util.OWLOntologyMerger ...

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48143583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档