Java Code Examples for org.apache.jena.rdf.model.Model#createProperty()

The following examples show how to use org.apache.jena.rdf.model.Model#createProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Service.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
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;
    }
 
Example 2
Source File: Service.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
private void getFieldPath(Set<LinkedList<QueryNode>> paths, LinkedList<QueryNode> path, HGQLSchema schema, Model model, JsonNode currentNode) {

        LinkedList<QueryNode> newPath = new LinkedList<>(path);
        String nodeMarker = currentNode.get("nodeId").asText();
        String nodeName = currentNode.get("name").asText();
        FieldConfig field = schema.getFields().get(nodeName);
        if (field == null) {
            throw new RuntimeException("field not found");
        }

        Property predicate = model.createProperty(field.getId());
        QueryNode queryNode = new QueryNode(predicate, nodeMarker);
        newPath.add(queryNode);
        paths.add(newPath);
        JsonNode fields = currentNode.get("fields");
        if (fields != null && !fields.isNull()) {
            getQueryPathsRecursive(fields, paths, newPath, schema);
        }
    }
 
Example 3
Source File: Service.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
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;
    }
 
Example 4
Source File: Service.java    From hypergraphql with Apache License 2.0 6 votes vote down vote up
private void getFieldPath(Set<LinkedList<QueryNode>> paths, LinkedList<QueryNode> path, HGQLSchema schema, Model model, JsonNode currentNode) {

        LinkedList<QueryNode> newPath = new LinkedList<>(path);
        String nodeMarker = currentNode.get("nodeId").asText();
        String nodeName = currentNode.get("name").asText();
        FieldConfig field = schema.getFields().get(nodeName);
        if (field == null) {
            throw new RuntimeException("field not found");
        }

        Property predicate = model.createProperty(field.getId());
        QueryNode queryNode = new QueryNode(predicate, nodeMarker);
        newPath.add(queryNode);
        paths.add(newPath);
        JsonNode fields = currentNode.get("fields");
        if (fields != null && !fields.isNull()) {
            getQueryPathsRecursive(fields, paths, newPath, schema);
        }
    }
 
Example 5
Source File: SDADatasetAccessor.java    From SDA with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Model makeSampleModel() {
	String BASE = "http://example/";
	
	Model model = ModelFactory.createDefaultModel();
	model.setNsPrefix("", BASE);
	Resource r1 = model.createResource(BASE + "r1");
	Resource r2 = model.createResource(BASE + "r2");
	Property p1 = model.createProperty(BASE + "p");
	Property p2 = model.createProperty(BASE + "p2");
	RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger);
	RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger);

	r1.addProperty(p1, v1).addProperty(p1, v2);
	r1.addProperty(p2, v1).addProperty(p2, v2);
	r2.addProperty(p1, v1).addProperty(p1, v2);

	return model;
}
 
Example 6
Source File: SDADatasetAccessor.java    From SDA with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Model makeSampleModel() {
	String BASE = "http://example/";
	
	Model model = ModelFactory.createDefaultModel();
	model.setNsPrefix("", BASE);
	Resource r1 = model.createResource(BASE + "r1");
	Resource r2 = model.createResource(BASE + "r2");
	Property p1 = model.createProperty(BASE + "p");
	Property p2 = model.createProperty(BASE + "p2");
	RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger);
	RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger);

	r1.addProperty(p1, v1).addProperty(p1, v2);
	r1.addProperty(p2, v1).addProperty(p2, v2);
	r2.addProperty(p1, v1).addProperty(p1, v2);

	return model;
}
 
Example 7
Source File: SpdxPackageVerificationCode.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a resource from this SPDX Verification Code
 * @param model
 * @return
 */
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_VERIFICATIONCODE);
	Resource r = model.createResource(type);
	if (this.excludedFileNames.size() > 0) {
		Property excludedFileProp = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, 
				SpdxRdfConstants.PROP_VERIFICATIONCODE_IGNORED_FILES);
		for (int i = 0; i < this.excludedFileNames.size(); i++) {
			r.addProperty(excludedFileProp, this.excludedFileNames.get(i));
		}
	}
	if (this.value != null  && !this.value.isEmpty()) {
		Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_VERIFICATIONCODE_VALUE);
		r.addProperty(valueProperty, this.value);
	}
	this.verificationCodeNode = r.asNode();
	this.verificationCodeResource = r;
	return r;
}
 
Example 8
Source File: SPDXCreatorInformation.java    From tools with Apache License 2.0 6 votes vote down vote up
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_CREATION_INFO);
	Resource r = model.createResource(type);
	if (creators != null && creators.length > 0) {
		Property nameProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE,
				SpdxRdfConstants.PROP_CREATION_CREATOR);
		for (int i = 0; i < creators.length; i++) {
			r.addProperty(nameProperty, this.creators[i]);
		}
	}
	if (this.comment != null) {
		Property commentProperty = model.createProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT);
		r.addProperty(commentProperty, this.comment);
	}
	// creation date
	if (this.createdDate != null) {
		Property createdDateProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CREATION_CREATED);
		r.addProperty(createdDateProperty, this.createdDate);
	}
	this.creatorNode = r.asNode();
	this.creatorResource = r;
	return r;
}
 
Example 9
Source File: SpdxPackageVerificationCode.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a resource from this SPDX Verification Code
 * @param model
 * @return
 */
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_VERIFICATIONCODE);
	Resource r = model.createResource(type);
	if (this.excludedFileNames.size() > 0) {
		Property excludedFileProp = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE,
				SpdxRdfConstants.PROP_VERIFICATIONCODE_IGNORED_FILES);
		for (int i = 0; i < this.excludedFileNames.size(); i++) {
			r.addProperty(excludedFileProp, this.excludedFileNames.get(i));
		}
	}
	if (this.value != null  && !this.value.isEmpty()) {
		Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_VERIFICATIONCODE_VALUE);
		r.addProperty(valueProperty, this.value);
	}
	this.verificationCodeNode = r.asNode();
	this.verificationCodeResource = r;
	return r;
}
 
Example 10
Source File: SPDXChecksum.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a resource from this SPDX Checksum
 * @param model
 * @return
 */
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_CHECKSUM);
	Resource r = model.createResource(type);
	if (algorithm != null) {
		Property algProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE,
				SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM);
		r.addProperty(algProperty, this.algorithm);
	}
	if (this.value != null) {
		Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE);
		r.addProperty(valueProperty, this.value);
	}
	this.checksumNode = r.asNode();
	this.checksumResource = r;
	return r;
}
 
Example 11
Source File: LicenseException.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * Searches the model for a exception with the ID
 * @param model
 * @param id
 * @return Node containing the exception or Null if none found
 */
public static Node findException(Model model, String id) {
	Property idProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, 
			SpdxRdfConstants.PROP_LICENSE_EXCEPTION_ID);
	Property typeProperty = model.getProperty(SpdxRdfConstants.RDF_NAMESPACE, 
			SpdxRdfConstants.RDF_PROP_TYPE);
	Property exceptionTypeProperty = model.getProperty(SpdxRdfConstants.SPDX_NAMESPACE,
			SpdxRdfConstants.CLASS_SPDX_LICENSE_EXCEPTION);
	Triple m = Triple.createMatch(null, idProperty.asNode(), null);
	ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);	
	while (tripleIter.hasNext()) {
		Triple t = tripleIter.next();
		if (t.getObject().toString(false).equals(id)) {
			Triple typeMatch = Triple.createMatch(t.getSubject(), typeProperty.asNode(), exceptionTypeProperty.asNode());
			ExtendedIterator<Triple> typeTripleIter = model.getGraph().find(typeMatch);
			if (typeTripleIter.hasNext()) {
				return t.getSubject();
			}
		}
	}
	return null;
}
 
Example 12
Source File: StageAltMain.java    From xcurator with Apache License 2.0 5 votes vote down vote up
private static Model makeData()
{
    Model model = ModelFactory.createDefaultModel() ;
    Resource r = model.createResource(NS+"r") ;
    Property p1 = model.createProperty(NS+"p1") ;
    Property p2 = model.createProperty(NS+"p2") ;
    model.add(r, p1, "xyz") ;
    model.add(r, p2, "abc") ;
    return model ;
}
 
Example 13
Source File: RDFToTopicMapConverter.java    From ontopia with Apache License 2.0 5 votes vote down vote up
private void buildMappings(Model model) throws MalformedURLException {
  mappings = new HashMap();
  Property mapsTo = model.createProperty(RTM_MAPSTO);
  StmtIterator it = model.listStatements(null, mapsTo, (RDFNode) null);
  while (it.hasNext()) {
    Statement stmt = (Statement) it.next();
    StatementHandler mapper = getMapper(stmt.getSubject(), stmt.getObject(), model);
    mappings.put(stmt.getSubject().getURI(), mapper);
  }
  it.close();
}
 
Example 14
Source File: SPDXChecksum.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a resource from this SPDX Checksum
 * @param model
 * @return
 */
public Resource createResource(Model model) {
	this.model = model;
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE +
			SpdxRdfConstants.CLASS_SPDX_CHECKSUM);
	
	Resource r;
	try {
		r = findSpdxChecksum(model, this);
	} catch (InvalidSPDXAnalysisException e) {
		// if we run into an error finding the checksum, we'll just create a new one
		r = null;
	}		// prevent duplicate checksum objects
	if (r == null) {
		r = model.createResource(type);
	}
	if (algorithm != null) {
		Property algProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, 
				SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM);
		Resource algResource = model.createResource(ALGORITHM_TO_URI.get(algorithm));
		r.addProperty(algProperty, algResource);
	}
	if (this.value != null) {
		Property valueProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE);
		r.addProperty(valueProperty, this.value);
	}
	this.checksumNode = r.asNode();
	this.checksumResource = r;
	return r;
}
 
Example 15
Source File: SPDXLicenseSet.java    From tools with Apache License 2.0 5 votes vote down vote up
protected Resource _createResource(Model model, Resource type) {
	Resource r = model.createResource(type);
	Property licProperty = model.createProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_SET_MEMEBER);
	Iterator<SPDXLicenseInfo> iter = this.licenseInfos.iterator();
	while (iter.hasNext()) {
		Resource licResource = iter.next().createResource(model);
		r.addProperty(licProperty, licResource);
	}
	return r;
}
 
Example 16
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.spdx.rdfparser.model.RdfModelObject#RdfModelObject(org.apache.jena.rdf.model.Model, org.apache.jena.graph.Node)}.
 * @throws InvalidSPDXAnalysisException 
 */
@Test
public void testRdfModelObjectModelNode() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Property p = model.createProperty(TEST_NAMESPACE, TEST_PROPNAME2);
	Resource r = model.createResource();
	r.addProperty(p, TEST_PROPVALUE1);
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	String result = empty.findSinglePropertyValue(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(TEST_PROPVALUE1, result);
}
 
Example 17
Source File: Service.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private Set<String> findRootIdentifiers(Model model, TypeConfig targetName) {

        Set<String> identifiers = new HashSet<>();
        Model currentmodel = ModelFactory.createDefaultModel();
        Resource res = currentmodel.createResource(targetName.getId());
        Property property = currentmodel.createProperty(RDF_TYPE);

        ResIterator iterator = model.listResourcesWithProperty(property, res);

        while (iterator.hasNext()) {
            identifiers.add(iterator.nextResource().toString());
        }
        return identifiers;
    }
 
Example 18
Source File: Service.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private Set<String> findRootIdentifiers(Model model, TypeConfig targetName) {

        Set<String> identifiers = new HashSet<>();
        Model currentmodel = ModelFactory.createDefaultModel();
        Resource res = currentmodel.createResource(targetName.getId());
        Property property = currentmodel.createProperty(RDF_TYPE);

        ResIterator iterator = model.listResourcesWithProperty(property, res);

        while (iterator.hasNext()) {
            identifiers.add(iterator.nextResource().toString());
        }
        return identifiers;
    }
 
Example 19
Source File: JenaUtil.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
public static Statement fromTuple(Model m, Tuple t, BasicUniverse u, Instance t2) {
	Resource s = (Resource) fromAtom(m, t.atom(1), u, t2);
	Property p = m.createProperty(String.valueOf(t.atom(2)));
	RDFNode o = fromAtom(m, t.atom(3), u, t2);
	return m.createStatement(s, p, o);
}
 
Example 20
Source File: ExTDB6.java    From xcurator with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    /// turn off the "No BGP optimizer warning"
    TDB.setOptimizerWarningFlag(false);

    final IRIFactory iriFactory = IRIFactory.semanticWebImplementation();

    final String DATASET_DIR_NAME = "data0";
    final Dataset data0 = TDBFactory.createDataset( DATASET_DIR_NAME );

    // show the currently registered names
    for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
        out.println("NAME="+it.next());
    }

    out.println("getting named model...");
    /// this is the OWL portion
    final Model model = data0.getNamedModel( MY_NS );
    out.println("Model := "+model);

    out.println("getting graph...");
    /// this is the DATA in that MODEL
    final Graph graph = model.getGraph();
    out.println("Graph := "+graph);

    if (graph.isEmpty()) {
        final Resource product1 = model.createResource(
                iriFactory.construct( MY_NS +"product/1" )
                    .toString() );

        final Property hasName = model.createProperty( MY_NS, "#hasName");
        final Statement stmt = model.createStatement(
                product1, hasName, model.createLiteral("Beach Ball","en") );
        out.println("Statement = " + stmt);

        model.add(stmt);

        // just for fun
        out.println("Triple := " + stmt.asTriple().toString());
    } else {
        out.println("Graph is not Empty; it has "+graph.size()+" Statements");
        long t0, t1;
        t0 = System.currentTimeMillis();
        final Query q = QueryFactory.create(
                "PREFIX exns: <"+MY_NS+"#>\n"+
                "PREFIX exprod: <"+MY_NS+"product/>\n"+
                " SELECT * "
                // if you don't provide the Model to the
                // QueryExecutionFactory below, then you'll need
                // to specify the FROM;
                // you *can* always specify it, if you want
                // +" FROM <"+MY_NS+">\n"
                // +" WHERE { ?node <"+MY_NS+"#hasName> ?name }"
                // +" WHERE { ?node exns:hasName ?name }"
                // +" WHERE { exprod:1 exns:hasName ?name }"
                +" WHERE { ?res ?pred ?obj }"
                );
        out.println("Query := "+q);
        t1 = System.currentTimeMillis();
        out.println("QueryFactory.TIME="+(t1 - t0));

        t0 = System.currentTimeMillis();
        final QueryExecution qExec = QueryExecutionFactory
                // if you query the whole DataSet,
                // you have to provide a FROM in the SparQL
                //.create(q, data0);
                .create(q, model);
        t1 = System.currentTimeMillis();
        out.println("QueryExecutionFactory.TIME="+(t1 - t0));

        try {
            t0 = System.currentTimeMillis();
            ResultSet rs = qExec.execSelect();
            t1 = System.currentTimeMillis();
            out.println("executeSelect.TIME="+(t1 - t0));
            while (rs.hasNext()) {
                QuerySolution sol = rs.next();
                out.println("Solution := "+sol);
                for (Iterator<String> names = sol.varNames(); names.hasNext(); ) {
                    final String name = names.next();
                    out.println("\t"+name+" := "+sol.get(name));
                }
            }
        } finally {
            qExec.close();
        }
    }
    out.println("closing graph");
    graph.close();
    out.println("closing model");
    model.close();
    //out.println("closing DataSetGraph");
    //dsg.close();
    out.println("closing DataSet");
    data0.close();
}