org.apache.jena.rdf.model.Model.createProperty()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.apache.jena.rdf.model.Model.createProperty()方法的一些代码示例,展示了Model.createProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Model.createProperty()方法的具体详情如下:
包路径:org.apache.jena.rdf.model.Model
类名称:Model
方法名:createProperty

Model.createProperty介绍

[英]Create a property with a given URI composed from a namespace part and a localname part by concatenating the strings.

This method may return an existing property with the correct URI and model, or it may construct a fresh one, as it sees fit.

Subsequent operations on the returned property may modify this model.
[中]通过连接字符串,使用由命名空间部分和localname部分组成的给定URI创建属性。
此方法可以返回具有正确URI和模型的现有属性,也可以根据需要构造新属性。
对返回属性的后续操作可能会修改此模型。

代码示例

代码示例来源:origin: google/data-transfer-project

private String createIndex(String url, String slug, SolidUtilities utilities) throws Exception {
 Model model = ModelFactory.createDefaultModel();
 Resource containerResource = model.createResource("#this");
 containerResource.addProperty(RDF.type, model.getResource(VCARD4.NS + "AddressBook"));
 containerResource.addProperty(
   model.createProperty(VCARD4.NS + "nameEmailIndex"),
   model.createResource("people.ttl"));
 containerResource.addProperty(
   model.createProperty(VCARD4.NS + "groupIndex"),
   model.createResource("groups.ttl"));
 containerResource.addProperty(DC_11.title, slug);
 return utilities.postContent(
   url,
   "index",
   BASIC_RESOURCE_TYPE,
   model);
}

代码示例来源:origin: vivo-project/Vitro

Model constructModel(Resource individual, String property) {
  Model model = ModelFactory.createDefaultModel();
  for (String uri : typeUris) {
    model.add(individual, model.createProperty(property), model.createResource(uri));
  }
  return model;
}

代码示例来源:origin: apache/odftoolkit

public void addObject(String subject, String predicate, String object) {
  Model model =getContextModel();
  Resource s = getResource(model, subject.trim());
  Property p = model.createProperty(predicate.trim());
  Resource o = getResource(model, object.trim());
  model.add(s, p, o);
}

代码示例来源:origin: apache/jena

private static void load2(Model model)
{
  Resource r2 = model.createResource(base1+"r2") ;
  Property p1 = model.createProperty(baseNS+"p1") ;
  model.add(r2, p1, "x1") ;
  model.add(r2, p1, "x2") ;
}

代码示例来源:origin: spdx/tools

protected Resource _createResource(Resource type) throws InvalidSPDXAnalysisException {
  Resource r = model.createResource(type);
  Property licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER);
  Resource licResource = this.license.createResource(this.modelContainer);
  r.addProperty(licProperty, licResource);
  Property exceptionProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_EXCEPTION);
  Resource exceptionResource = this.exception.createResource(modelContainer);
  r.addProperty(exceptionProperty, exceptionResource);
  return r;
}

代码示例来源:origin: apache/jena

private void doTestRDFSSimple(String level) {
  Model model = ModelFactory.createDefaultModel();
  String NS = "http://jena.hpl.hp.com/example#";
  Property prop = model.createProperty(NS + "prop");
  model.add(prop, RDF.type, RDF.Property);
  Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(null);
  reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, level);
  InfModel im = ModelFactory.createInfModel(reasoner, model);
  assertTrue( im.contains(prop, RDFS.subPropertyOf, prop) );
}

代码示例来源:origin: apache/jena

/**
 * Test chainging rules from axioms which broke while trying to
 * fix about test case.
 */
public void testFactChainRules() {
  Model facts = ModelFactory.createDefaultModel();
  String NS = PrintUtil.egNS;
  Property mother = facts.createProperty(NS + "mother");
  Resource female = facts.createProperty(NS + "Female");
  mother.addProperty(RDFS.range, female);
  List<Rule> rules = Rule.parseRules(
      "-> tableAll(). \n" +
      "[rdfs6:  (?p rdfs:subPropertyOf ?q), notEqual(?p,?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ] \n" +
       "-> (eg:range rdfs:subPropertyOf rdfs:range). \n" +
       "-> (rdfs:range rdfs:subPropertyOf eg:range). \n" );
  GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
  reasoner.setTransitiveClosureCaching(true);
  InfModel inf = ModelFactory.createInfModel(reasoner, facts);
  Property egRange = inf.createProperty(NS + "range");
  TestUtil.assertIteratorValues(this,
        inf.listStatements(null, egRange, (RDFNode)null),
        new Object[] {inf.createStatement(mother, egRange, female)} );
}

代码示例来源:origin: semantic-integration/hypergraphql

private Model buildModel(QuerySolution results, JsonNode currentNode , HGQLSchema schema) {
  Model model = ModelFactory.createDefaultModel();
  FieldConfig propertyString = schema.getFields().get(currentNode.get("name").asText());
  TypeConfig targetTypeString = schema.getTypes().get(currentNode.get("targetName").asText());
  populateModel(results, currentNode, model, propertyString, targetTypeString);
  QueryFieldConfig queryField = schema.getQueryFields().get(currentNode.get("name").asText());
  if (queryField != null) {
    String typeName = (currentNode.get("alias").isNull()) ? currentNode.get("name").asText() : currentNode.get("alias").asText();
    Resource object = results.getResource(currentNode.get("nodeId").asText());
    Resource subject = model.createResource(HGQL_QUERY_URI);
    Property predicate = model.createProperty("", HGQL_QUERY_NAMESPACE + typeName);
    model.add(subject, predicate, object);
  }
  return model;
}

代码示例来源:origin: apache/jena

private static void load3(Model model)
{
  Resource r3 = model.createResource(base1+"r3") ;
  Property p1 = model.createProperty(baseNS+"p2") ;
  model.add(r3, p1, "x1") ;
  model.add(r3, p1, "x2") ;
}

代码示例来源:origin: google/data-transfer-project

private String createPeopleFile(
  String baseUrl,
  String containerUrl,
  Map<String, VCard> importedPeople,
  SolidUtilities utilities) throws Exception {
 Model peopleModel = ModelFactory.createDefaultModel();
 Resource indexResource = peopleModel.createResource("index.ttl#this");
 for (String insertedId : importedPeople.keySet()) {
  VCard insertedPerson = importedPeople.get(insertedId);
  String relativePath = insertedId.replace(containerUrl, "");
  Resource personResource = peopleModel.createResource(relativePath + "#this");
  if (insertedPerson.getFormattedName() != null) {
   personResource.addProperty(VCARD4.fn, insertedPerson.getFormattedName().getValue());
  }
  personResource.addProperty(
    peopleModel.createProperty(VCARD4.NS, "inAddressBook"),
    indexResource);
 }
 return utilities.postContent(
   baseUrl + containerUrl,
   "people",
   BASIC_RESOURCE_TYPE,
   peopleModel);
}

代码示例来源:origin: org.spdx/spdx-tools

protected Resource _createResource(Resource type) throws InvalidSPDXAnalysisException {
  Resource r = model.createResource(type);
  Property licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER);
  Resource licResource = this.license.createResource(this.modelContainer);
  r.addProperty(licProperty, licResource);
  Property exceptionProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_EXCEPTION);
  Resource exceptionResource = this.exception.createResource(modelContainer);
  r.addProperty(exceptionProperty, exceptionResource);
  return r;
}

代码示例来源:origin: org.apache.jena/jena-core

private void doTestRDFSSimple(String level) {
  Model model = ModelFactory.createDefaultModel();
  String NS = "http://jena.hpl.hp.com/example#";
  Property prop = model.createProperty(NS + "prop");
  model.add(prop, RDF.type, RDF.Property);
  Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(null);
  reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel, level);
  InfModel im = ModelFactory.createInfModel(reasoner, model);
  assertTrue( im.contains(prop, RDFS.subPropertyOf, prop) );
}

代码示例来源:origin: org.apache.jena/jena-core

/**
 * Fact rules with non-empty bodyies failed to fire.
 */
public void testFactRules() {
  Model facts = ModelFactory.createDefaultModel();
  String NS = PrintUtil.egNS;
  Property p = facts.createProperty(NS + "p");
  List<Rule> rules = Rule.parseRules("makeTemp(?x) -> (?x, eg:p, eg:z). " +
      "makeTemp(?x) makeTemp(?y) -> (?x, eg:p, ?y) . " +
      "(?x, eg:p, eg:z) -> (?a, eg:p, eg:b). " +
      "-> [ (eg:a eg:p eg:y) <- ]."
      );
  GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
  InfModel inf = ModelFactory.createInfModel(reasoner, facts);
  inf.prepare();
  TestUtil.assertIteratorLength(inf.listStatements(null, p, (RDFNode)null), 4);
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static void renameProperty(Model model, Property p, String uri) {
  List<Statement> stmts = model.listStatements(null, p, (RDFNode)null).toList();
  model.remove(stmts);
  for(Statement stmt : stmts) {
    Property newProperty = model.createProperty(uri);
    model.add(stmt.getSubject(), newProperty, stmt.getObject());
  }
}

代码示例来源:origin: semantic-integration/hypergraphql

private Model buildModel(QuerySolution results, JsonNode currentNode , HGQLSchema schema) {
  Model model = ModelFactory.createDefaultModel();
  FieldConfig propertyString = schema.getFields().get(currentNode.get("name").asText());
  TypeConfig targetTypeString = schema.getTypes().get(currentNode.get("targetName").asText());
  populateModel(results, currentNode, model, propertyString, targetTypeString);
  QueryFieldConfig queryField = schema.getQueryFields().get(currentNode.get("name").asText());
  if (queryField != null) {
    String typeName = (currentNode.get("alias").isNull()) ? currentNode.get("name").asText() : currentNode.get("alias").asText();
    Resource object = results.getResource(currentNode.get("nodeId").asText());
    Resource subject = model.createResource(HGQL_QUERY_URI);
    Property predicate = model.createProperty("", HGQL_QUERY_NAMESPACE + typeName);
    model.add(subject, predicate, object);
  }
  return model;
}

代码示例来源:origin: apache/jena

private static void load2(Model model)
{
  Resource r2 = model.createResource(base1+"r2") ;
  Property p1 = model.createProperty(baseNS+"p1") ;
  model.add(r2, p1, "x1") ;
  model.add(r2, p1, "x2") ;
}

代码示例来源:origin: io.github.luzzu/luzzu-ld-qualitymetrics-commons

public Triple getTriple(){
  Resource _sbj, _prd;
  RDFNode _obj;
  
  if (isSubjectBlank) _sbj = ModelFactory.createDefaultModel().createResource(new AnonId(this.subject));
  else _sbj = ModelFactory.createDefaultModel().createResource(subject);
    
  _prd = ModelFactory.createDefaultModel().createProperty(predicate);
  
  if (isObjectBlank) _obj = ModelFactory.createDefaultModel().createResource(new AnonId(this.object));
  else if (isObjectLiteral) _obj = ModelFactory.createDefaultModel().createLiteral(object);
  else _obj = ModelFactory.createDefaultModel().createResource(object);
  
  return new Triple(_sbj.asNode(), _prd.asNode(), _obj.asNode());
}

代码示例来源:origin: apache/jena

@Override
public void setUp()
{
  super.setUp();
  S = model.createResource("http://nowhere.man/subject");
  P = model.createProperty("http://nowhere.man/predicate");
}

代码示例来源:origin: apache/jena

/**
 * Fact rules with non-empty bodyies failed to fire.
 */
public void testFactRules() {
  Model facts = ModelFactory.createDefaultModel();
  String NS = PrintUtil.egNS;
  Property p = facts.createProperty(NS + "p");
  List<Rule> rules = Rule.parseRules("makeTemp(?x) -> (?x, eg:p, eg:z). " +
      "makeTemp(?x) makeTemp(?y) -> (?x, eg:p, ?y) . " +
      "(?x, eg:p, eg:z) -> (?a, eg:p, eg:b). " +
      "-> [ (eg:a eg:p eg:y) <- ]."
      );
  GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
  InfModel inf = ModelFactory.createInfModel(reasoner, facts);
  inf.prepare();
  TestUtil.assertIteratorLength(inf.listStatements(null, p, (RDFNode)null), 4);
}

代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-resources-sparqlqc

public static void renameProperty(Model model, Property p, String uri) {
  List<Statement> stmts = model.listStatements(null, p, (RDFNode)null).toList();
  model.remove(stmts);
  for(Statement stmt : stmts) {
    Property newProperty = model.createProperty(uri);
    model.add(stmt.getSubject(), newProperty, stmt.getObject());
  }
}

相关文章

Model类方法