本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.createDatatypeProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.createDatatypeProperty方法的具體用法?Java OntModel.createDatatypeProperty怎麽用?Java OntModel.createDatatypeProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.createDatatypeProperty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Build
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void Build(String path) throws IOException {
List<HNode> sortedLeafHNodes = new ArrayList<HNode>();
worksheet.getHeaders().getSortedLeafHNodes(sortedLeafHNodes);
OntModel autoOntology = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
String ns = Namespaces.KARMA;
autoOntology.setNsPrefix("karma", ns);
OntClass topClass = autoOntology.createClass( ns + worksheet.getTitle().replaceAll(" ", "_")); // replace blank spaces with undrscore
for (HNode hNode : sortedLeafHNodes){
DatatypeProperty dp = autoOntology.createDatatypeProperty(ns+hNode.getColumnName().trim().replaceAll(" ", "_"));
dp.addDomain(topClass);
dp.addRange(XSD.xstring);
}
// OntClass thingClass = autoOntology.createClass(Uris.THING_URI);
ObjectProperty op = autoOntology.createObjectProperty(ns + "relatedTo");
op.addDomain(topClass);
// op.addRange(thingClass);
Writer outUTF8 =null;
try {
outUTF8 = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path), "UTF8"));
autoOntology.write(outUTF8, null);
outUTF8.flush();
outUTF8.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例2: doTestDatatypeRangeValidation
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private void doTestDatatypeRangeValidation(RDFDatatype over12Type, OntModelSpec spec) {
OntModel ont = ModelFactory.createOntologyModel(spec);
String NS = "http://jena.hpl.hp.com/example#";
Resource over12 = ont.createResource( over12Type.getURI() );
DatatypeProperty hasValue = ont.createDatatypeProperty(NS + "hasValue");
hasValue.addRange( over12 );
ont.createResource(NS + "a").addProperty(hasValue, "15", over12Type);
ont.createResource(NS + "b").addProperty(hasValue, "16", over12Type);
ont.createResource(NS + "c").addProperty(hasValue, "10", over12Type);
ValidityReport validity = ont.validate();
assertTrue (! validity.isValid());
Iterator<Report> ritr = validity.getReports();
while (ritr.hasNext()) {
System.out.println("For spec '" + spec + "': " + ritr.next().toString());
}
ont.write(System.out);
// Check culprit reporting
ValidityReport.Report report = (validity.getReports().next());
Triple culprit = (Triple)report.getExtension();
assertEquals(culprit.getSubject().getURI(), NS + "c");
assertEquals(culprit.getPredicate(), hasValue.asNode());
// ont.createTypedLiteral("15", over12Type).getValue();
// ont.createTypedLiteral("16", over12Type).getValue();
// ont.createTypedLiteral("12", over12Type).getValue();
}