【发布时间】:2023-03-05 07:42:01
【问题描述】:
问题听起来很简单:我想在我的本体中为个人创建一个数据属性作为 XSD:string。
我可以创建 XSD:DateTime、XSD:Float 或 XSD:int 的属性,但如果我使用 XSD:string,我会得到一个无类型的属性!
我创建了一个最小的示例,它创建了一个具有一个类、一个个体和两个数据属性的本体。一个 DateTime,其工作方式与预期相同,一个字符串,在本体中没有类型。
我尝试使用 Jena 3.4 和 3.0.1 版本,但不知道该由谁来修复它。
package dataproperty;
import java.io.FileOutputStream;
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
public class DataProperty {
public static void main(String[] args) throws Exception {
OntModel model = ModelFactory.createOntologyModel();
String OWLPath = "DataProp.owl";
try{
String NS = "http://www.example.org/ontology.owl#";
//Create Ontology
model.createClass(NS+"Test");
Resource r = model.createResource(NS+"Test");
model.createIndividual(NS+"Indi1", r);
r = model.createResource(NS+"Indi1");
model.createDatatypeProperty(NS+"Name");
model.createDatatypeProperty(NS+"Date");
//Add Data Properties
Property p = model.getProperty(NS+"Name");
model.add(r, p, ResourceFactory.createTypedLiteral("MyName", XSDDatatype.XSDstring));
p = model.getProperty(NS+"Date");
model.add(r, p, ResourceFactory.createTypedLiteral("2017-08-12T09:03:40", XSDDatatype.XSDdateTime));
//Store the ontology
FileOutputStream output = null;
output = new FileOutputStream(OWLPath);
model.write(output);
}catch (Exception e) {
System.out.println("Error occured: " + e);
throw new Exception(e.getMessage());
}
}
}
【问题讨论】:
-
文字默认是字符串,所以这些值是字符串。
-
但据我所知,您应该始终指定数据类型,我得到“MyName”^^XSD:string 是不是正确的?
-
看起来字符串类型在 RDF 1.1 与 RDF 1.0 中发生了变化,但我想 Jena 使用 RDF 1.0 的“普通文字”作为字符串,as the documentation suggests。
-
实际上,here 说:“没有语言标签的普通文字(也称为“简单文字”)的数据类型具有数据类型 xsd:string。”
-
没错。另外,请参阅Jena explanation