Java Code Examples for org.eclipse.rdf4j.model.ValueFactory#createIRI()

The following examples show how to use org.eclipse.rdf4j.model.ValueFactory#createIRI() . 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: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeMultipleB() throws Exception {
	String update = "insert data { <urn:1> <urn:p1> <urn:v> . <urn:1> <urn:blank> [] . <urn:2> <urn:p2> <urn:3> . } ";
	conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();

	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE <urn:1> <urn:2> ");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	IRI urn1 = vf.createIRI("urn:1");
	IRI p1 = vf.createIRI("urn:p1");
	IRI p2 = vf.createIRI("urn:p2");
	IRI urn2 = vf.createIRI("urn:2");
	IRI blank = vf.createIRI("urn:blank");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);

		assertTrue(result.contains(urn1, p1, null));
		assertTrue(result.contains(urn1, blank, null));
		assertTrue(result.contains(urn2, p2, null));
	}
}
 
Example 2
Source File: LinearTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	repo = OptimisticIsolationTest.getEmptyInitializedRepository(LinearTest.class);
	lf = repo.getValueFactory();
	ValueFactory uf = repo.getValueFactory();
	PAINTER = uf.createIRI(NS, "Painter");
	PAINTS = uf.createIRI(NS, "paints");
	PAINTING = uf.createIRI(NS, "Painting");
	YEAR = uf.createIRI(NS, "year");
	PERIOD = uf.createIRI(NS, "period");
	PICASSO = uf.createIRI(NS, "picasso");
	REMBRANDT = uf.createIRI(NS, "rembrandt");
	GUERNICA = uf.createIRI(NS, "guernica");
	JACQUELINE = uf.createIRI(NS, "jacqueline");
	NIGHTWATCH = uf.createIRI(NS, "nightwatch");
	ARTEMISIA = uf.createIRI(NS, "artemisia");
	DANAE = uf.createIRI(NS, "danaƫ");
	JACOB = uf.createIRI(NS, "jacob");
	ANATOMY = uf.createIRI(NS, "anatomy");
	BELSHAZZAR = uf.createIRI(NS, "belshazzar");
	a = repo.getConnection();
	b = repo.getConnection();
}
 
Example 3
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeB() throws Exception {
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:b");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory f = conn.getValueFactory();
	IRI b = f.createIRI("http://example.org/b");
	IRI p = f.createIRI("http://example.org/p");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);
		Set<Resource> subjects = result.filter(null, p, b).subjects();
		assertNotNull(subjects);
		for (Value subject : subjects) {
			if (subject instanceof BNode) {
				assertTrue(result.contains(null, null, subject));
			}
		}
	}
}
 
Example 4
Source File: HalyardTableUtilsTest.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncateTable() throws Exception {
    ValueFactory vf = SimpleValueFactory.getInstance();
    Resource subj = vf.createIRI("http://whatever/subj/");
    IRI pred = vf.createIRI("http://whatever/pred/");
    Value expl = vf.createLiteral("explicit");
    for (KeyValue kv : HalyardTableUtils.toKeyValues(subj, pred, expl, null, false, System.currentTimeMillis())) {
            table.put(new Put(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), kv.getTimestamp()).add(kv));
    }
    table.flushCommits();
    try (ResultScanner rs = table.getScanner(HalyardTableUtils.scan(subj, pred, expl, null))) {
        assertNotNull(rs.next());
    }
    table = HalyardTableUtils.truncateTable(table);
    try (ResultScanner rs = table.getScanner(HalyardTableUtils.scan(subj, pred, expl, null))) {
        assertNull(rs.next());
    }
}
 
Example 5
Source File: GeoTemporalProviderTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void twoSubjOneFilter_test() throws Exception {
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final Value geo = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
    final Value temp = vf.createLiteral(new TemporalInstantRfc3339(2015, 12, 30, 12, 00, 0).toString());
    final IRI tempPred = vf.createIRI(URI_PROPERTY_AT_TIME);
    final String query =
        "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" +
        "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" +
        "PREFIX time: <tag:rya-rdf.org,2015:temporal#>" +
        "SELECT * WHERE { " +
            "?subj <" + tempPred + "> ?time ."+
            "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " +
            "?subj2 <" + tempPred + "> ?time2 ."+
            "?subj2 <" + GeoConstants.GEO_AS_WKT + "> ?loc2 . " +
            " FILTER(geos:sfContains(?loc, " + geo + ")) . " +
            " FILTER(time:equals(?time, " + temp + ")) . " +
        "}";
    final QuerySegment<EventQueryNode> node = getQueryNode(query);
    final List<EventQueryNode> nodes = provider.getExternalSets(node);
    assertEquals(1, nodes.size());
}
 
Example 6
Source File: MonotonicTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	repo = OptimisticIsolationTest.getEmptyInitializedRepository(MonotonicTest.class);
	lf = repo.getValueFactory();
	ValueFactory uf = repo.getValueFactory();
	PAINTER = uf.createIRI(NS, "Painter");
	PAINTS = uf.createIRI(NS, "paints");
	PAINTING = uf.createIRI(NS, "Painting");
	YEAR = uf.createIRI(NS, "year");
	PERIOD = uf.createIRI(NS, "period");
	PICASSO = uf.createIRI(NS, "picasso");
	REMBRANDT = uf.createIRI(NS, "rembrandt");
	GUERNICA = uf.createIRI(NS, "guernica");
	JACQUELINE = uf.createIRI(NS, "jacqueline");
	NIGHTWATCH = uf.createIRI(NS, "nightwatch");
	ARTEMISIA = uf.createIRI(NS, "artemisia");
	DANAE = uf.createIRI(NS, "danaƫ");
	JACOB = uf.createIRI(NS, "jacob");
	ANATOMY = uf.createIRI(NS, "anatomy");
	BELSHAZZAR = uf.createIRI(NS, "belshazzar");
	a = repo.getConnection();
	b = repo.getConnection();
}
 
Example 7
Source File: MongoGeoIndexerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithPredicate() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        // query with correct Predicate
        assertEquals(Sets.newHashSet(statement),
                getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));

        // query with wrong predicate
        assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createIRI("other:pred"))))));
    }
}
 
Example 8
Source File: NoReification.java    From inception with Apache License 2.0 5 votes vote down vote up
private List<Statement> listStatements(TupleQuery aQuery, boolean aIncludeInferred)
{
    aQuery.setIncludeInferred(aIncludeInferred);
    
    try (TupleQueryResult result = aQuery.evaluate()) {
        ValueFactory vf = SimpleValueFactory.getInstance();
        
        List<Statement> statements = new ArrayList<>();
        while (result.hasNext()) {
            BindingSet bindings = result.next();
            if (bindings.size() == 0) {
                continue;
            }
            
            // LOG.trace("[{}] Bindings: {}", toHexString(hashCode()), bindings);
            
            Binding subj = bindings.getBinding(VAR_SUBJECT_NAME);
            Binding pred = bindings.getBinding(VAR_PREDICATE_NAME);
            Binding obj = bindings.getBinding(VAR_OBJECT_NAME);

            IRI subject = vf.createIRI(subj.getValue().stringValue());
            IRI predicate = vf.createIRI(pred.getValue().stringValue());
            Statement stmt = vf.createStatement(subject, predicate, obj.getValue());
            
            // Avoid duplicate statements
            if (!statements.contains(stmt)) {
                statements.add(stmt);
            }
        }
        return statements;
    }
}
 
Example 9
Source File: MemInferencingTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
	public void testPersistence() {
		File datadir = Files.newTemporaryFolder();

		SchemaCachingRDFSInferencer sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
		SailRepository repo = new SailRepository(sailStack);
		repo.initialize();
		ValueFactory vf = repo.getValueFactory();

		IRI s1 = vf.createIRI("foo:s1");
		IRI c2 = vf.createIRI("foo:c2");
		IRI c1 = vf.createIRI("foo:c1");

		try (RepositoryConnection conn = repo.getConnection()) {
			conn.begin();
			conn.add(s1, RDF.TYPE, c1);
			conn.add(c1, RDFS.SUBCLASSOF, c2);
			conn.commit();
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
		repo.shutDown();

		// re-init
//		sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
//		repo = new SailRepository(sailStack);
		repo.initialize();

		try (RepositoryConnection conn = repo.getConnection()) {
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
	}
 
Example 10
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDescribeF() throws Exception {
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:f");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	IRI f = vf.createIRI("http://example.org/f");
	IRI p = vf.createIRI("http://example.org/p");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);

		assertNotNull(result);
		assertEquals(4, result.size());
		Set<Value> objects = result.filter(f, p, null).objects();
		assertNotNull(objects);
		for (Value object : objects) {
			if (object instanceof BNode) {
				Set<Value> childObjects = result.filter((BNode) object, null, null).objects();
				assertNotNull(childObjects);
				for (Value childObject : childObjects) {
					if (childObject instanceof BNode) {
						assertTrue(result.contains((BNode) childObject, null, null));
					}
				}
			}
		}
	}
}
 
Example 11
Source File: MongoGeoIndexerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearch() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));

        // test a ring outside the point
        final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
        final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
        final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
    }
}
 
Example 12
Source File: GeoWaveIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithContext() throws Exception {
    // test a ring around dc
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(conf);

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        // query with correct context
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));

        // query with wrong context
        Assert.assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createIRI("foo:context2")))));
    }
}
 
Example 13
Source File: MongoGeoIndexerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDcSearchWithSubjectAndContext() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource subject = vf.createIRI("foo:subj");
        final IRI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createIRI("foo:context");

        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();

        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        // query with correct context subject
        assertEquals(Sets.newHashSet(statement),
                getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));

        // query with wrong context
        assertEquals(Sets.newHashSet(),
                getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createIRI("foo:context2")))));

        // query with wrong subject
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createIRI("foo:subj2")))));
    }
}
 
Example 14
Source File: RdfControllerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void updateQuery() throws Exception {
    this.mockMvc.perform(get("/queryrdf")
            .param("query", "INSERT \n DATA\n {\n <http://mynamespace/ProductType1> <http://mynamespace#pred1> \"test\" }"))
            .andExpect(status().isOk());

    ValueFactory vf = repository.getValueFactory();
    RepositoryConnection con = repository.getConnection();

    IRI s = vf.createIRI("http://mynamespace/ProductType1");
    IRI p = vf.createIRI("http://mynamespace#pred1");
    Literal o = vf.createLiteral("test");

    assertTrue(con.getStatements(s, p, o, false).hasNext());
}
 
Example 15
Source File: GeoIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
public void testAntiMeridianSearch() throws Exception {
    // verify that a search works if the bounding box crosses the anti meridian
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(conf);

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final Resource context = vf.createIRI("foo:context");

        final Resource subjectEast = vf.createIRI("foo:subj:east");
        final IRI predicateEast = GeoConstants.GEO_AS_WKT;
        final Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Statement statementEast = vf.createStatement(subjectEast, predicateEast, objectEast, context);
        f.storeStatement(convertStatement(statementEast));

        final Resource subjectWest = vf.createIRI("foo:subj:west");
        final IRI predicateWest = GeoConstants.GEO_AS_WKT;
        final Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Statement statementWest = vf.createStatement(subjectWest, predicateWest, objectWest, context);
        f.storeStatement(convertStatement(statementWest));

        f.flush();

        final double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };

        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));

        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});

        Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
    }
}
 
Example 16
Source File: ModificationTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	repo = OptimisticIsolationTest.getEmptyInitializedRepository(ModificationTest.class);
	ValueFactory uf = repo.getValueFactory();
	PAINTER = uf.createIRI(NS, "Painter");
	PICASSO = uf.createIRI(NS, "picasso");
	con = repo.getConnection();
}
 
Example 17
Source File: DeadLockTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	repo = OptimisticIsolationTest.getEmptyInitializedRepository(DeadLockTest.class);
	ValueFactory uf = repo.getValueFactory();
	PAINTER = uf.createIRI(NS, "Painter");
	PICASSO = uf.createIRI(NS, "picasso");
	REMBRANDT = uf.createIRI(NS, "rembrandt");
	a = repo.getConnection();
	b = repo.getConnection();
}
 
Example 18
Source File: MongoGeoTemporalIndexerIT.java    From rya with Apache License 2.0 5 votes vote down vote up
private static RyaStatement statement(final TemporalInstant instant) {
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final Resource subject = vf.createIRI("uri:test");
    final IRI predicate = vf.createIRI("Property:atTime");
    final Value object = vf.createLiteral(instant.toString());
    return RdfToRyaConversions.convertStatement(vf.createStatement(subject, predicate, object));
}
 
Example 19
Source File: UUID.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public IRI evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
	if (args.length > 0) {
		throw new ValueExprEvaluationException("UUID requires 0 arguments, got " + args.length);
	}

	IRI uri = valueFactory.createIRI("urn:uuid:" + java.util.UUID.randomUUID().toString());

	return uri;
}
 
Example 20
Source File: KBProperty.java    From inception with Apache License 2.0 4 votes vote down vote up
public void write(RepositoryConnection aConn, KnowledgeBase kb)
{
    ValueFactory vf = aConn.getValueFactory();
    IRI subject = vf.createIRI(identifier);

    originalStatements.clear();

    Statement typeStmt = vf.createStatement(subject, kb.getTypeIri(), kb.getPropertyTypeIri());
    originalStatements.add(typeStmt);
    aConn.add(typeStmt);

    if (isNotBlank(name)) {
        Literal nameLiteral;
        if (language != null) {
            nameLiteral = vf.createLiteral(name, language);
        }
        else if (kb.getDefaultLanguage() != null) {
            nameLiteral = vf.createLiteral(name, kb.getDefaultLanguage());
        }
        else {
            nameLiteral = vf.createLiteral(name);
        }
        Statement nameStmt = vf.createStatement(subject, kb.getPropertyLabelIri(), nameLiteral);
        originalStatements.add(nameStmt);
        aConn.add(nameStmt);
    }

    if (isNotBlank(description)) {
        Literal descriptionLiteral;
        if (language == null) {
            descriptionLiteral = vf.createLiteral(description);
        }
        else {
            descriptionLiteral = vf.createLiteral(description, language);
        }
        Statement descStmt = vf.createStatement(subject, kb.getPropertyDescriptionIri(),
                descriptionLiteral);
        originalStatements.add(descStmt);
        aConn.add(descStmt);
    }

    if (domain != null) {
        Statement domainStmt = vf
            .createStatement(subject, RDFS.DOMAIN, vf.createLiteral(domain.toString()));
        originalStatements.add(domainStmt);
        aConn.add(domainStmt);
    }

    if (range != null) {
        Statement rangeStmt = vf
            .createStatement(subject, RDFS.RANGE, vf.createLiteral(range.toString()));
        originalStatements.add(rangeStmt);
        aConn.add(rangeStmt);
    }
}