Java Code Examples for org.eclipse.rdf4j.model.impl.SimpleValueFactory#getInstance()

The following examples show how to use org.eclipse.rdf4j.model.impl.SimpleValueFactory#getInstance() . 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: MongoFreeTextIndexerIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testContextSearch() throws Exception {
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();

        final ValueFactory vf = SimpleValueFactory.getInstance();
        final IRI subject = vf.createIRI("foo:subj");
        final IRI predicate = vf.createIRI(RDFS.COMMENT.toString());
        final Value object = vf.createLiteral("this is a new hat");
        final IRI context = vf.createIRI("foo:context");

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

        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
        assertEquals(Sets.newHashSet(),
                getSet(f.queryText("hat", new StatementConstraints().setContext(vf.createIRI("foo:context2")))));
    }
}
 
Example 2
Source File: SPARQLQueryBuilderTest.java    From inception with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLabelStartingWith_OLIA_FTS() throws Exception
{
    ValueFactory vf = SimpleValueFactory.getInstance();
    
    kb.setFullTextSearchIri(IriConstants.FTS_LUCENE);
    kb.setLabelIri(vf.createIRI("http://purl.org/olia/system.owl#hasTag"));
    
    importDataFromFile(rdf4jLocalRepo, "src/test/resources/data/penn.owl");
    
    List<KBHandle> results = asHandles(rdf4jLocalRepo, SPARQLQueryBuilder
            .forInstances(kb)
            .withLabelStartingWith("N"));
    
    assertThat(results).extracting(KBHandle::getIdentifier).doesNotHaveDuplicates();
    assertThat(results).isNotEmpty();
    assertThat(results).extracting(KBHandle::getUiLabel)
            .containsExactlyInAnyOrder("NN", "NNP", "NNPS", "NNS");
}
 
Example 3
Source File: GeoTemporalProviderTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void twoPatternsTwoFiltersNotValid_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);
    //Only handles geo and temporal filters
    final String query =
        "PREFIX geo: <http://www.opengis.net/ont/geosparql#>" +
        "PREFIX geos: <http://www.opengis.net/def/function/geosparql/>" +
        "PREFIX text: <http://rdf.useekm.com/fts#text>" +
        "SELECT * WHERE { " +
            "?subj <" + tempPred + "> ?time ."+
            "?subj <" + GeoConstants.GEO_AS_WKT + "> ?loc . " +
            " FILTER(geos:sfContains(?loc, " + geo + ")) . " +
            " FILTER(text:equals(?time, " + temp + ")) . " +
        "}";
    final QuerySegment<EventQueryNode> node = getQueryNode(query);
    final List<EventQueryNode> nodes = provider.getExternalSets(node);
    assertEquals(0, nodes.size());
}
 
Example 4
Source File: FilterEvaluatorTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void matches() throws Exception {
    // Read the filter object from a SPARQL query.
    final Filter filter = getFilter(
            "SELECT * " +
            "WHERE { " +
                "FILTER(?age < 10)" +
                "?person <urn:age> ?age " +
            "}");

    // Create the input binding set.
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("person", vf.createIRI("urn:Alice"));
    bs.addBinding("age", vf.createLiteral(9));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bs);

    // Test the evaluator.
    assertTrue( FilterEvaluator.make(filter).filter(visBs) );
}
 
Example 5
Source File: HalyardExportJDBCTypesTest.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
    ValueFactory vf = SimpleValueFactory.getInstance();
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), TABLE, true, 0, true, 0, null, null);
    sail.initialize();
    for (int i=1; i<10; i++) {
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/date"), vf.createLiteral(new Date(100 + i, i, i)));
        Date d = new Date(100 + i, i, i, i, i, i);
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/time"), vf.createLiteral(d));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/timestamp"), vf.createLiteral(new Date(d.getTime() + i))); // add millis
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/string"), vf.createLiteral("value" + i));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/boolean"), vf.createLiteral(i < 5));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/byte"), vf.createLiteral((byte)i));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/double"), vf.createLiteral((double)i/100.0));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/float"), vf.createLiteral((float)i/10.0));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/int"), vf.createLiteral(i * 100));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/long"), vf.createLiteral((long)i * 10000000000l));
        sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/short"), vf.createLiteral((short)(i * 10)));
    }
    sail.commit();
    sail.shutDown();
}
 
Example 6
Source File: GeoTemporalProviderTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void twoPatternsNoFilter_test() throws Exception {
    final ValueFactory vf = SimpleValueFactory.getInstance();
    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 . " +
        "}";
    final QuerySegment<EventQueryNode> node = getQueryNode(query);
    final List<EventQueryNode> nodes = provider.getExternalSets(node);
    assertEquals(0, nodes.size());
}
 
Example 7
Source File: SPARQLJSONTupleTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testNonStandardOrdered() throws Exception {
	SPARQLResultsJSONParser parser = new SPARQLResultsJSONParser(SimpleValueFactory.getInstance());
	QueryResultCollector handler = new QueryResultCollector();
	parser.setQueryResultHandler(handler);

	InputStream stream = this.getClass().getResourceAsStream("/sparqljson/non-standard-ordered.srj");
	assertNotNull("Could not find test resource", stream);
	parser.parseQueryResult(stream);

	// there must be 1 variable
	assertEquals(1, handler.getBindingNames().size());

	// first must be called "Concept", etc.,
	assertEquals("Concept", handler.getBindingNames().get(0));

	// -1 results
	assertEquals(100, handler.getBindingSets().size());
}
 
Example 8
Source File: StatementPatternProcessorIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void singlePattern_singleStatement() throws Exception {
    // Enumerate some topics that will be re-used
    final String ryaInstance = UUID.randomUUID().toString();
    final UUID queryId = UUID.randomUUID();
    final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
    final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);

    // Setup a topology.
    final String query = "SELECT * WHERE { ?person <urn:talksTo> ?otherPerson }";
    final TopologyFactory factory = new TopologyFactory();
    final TopologyBuilder builder = factory.build(query, statementsTopic, resultsTopic, new RandomUUIDFactory());

    // Create a statement that generate an SP result.
    final ValueFactory vf = SimpleValueFactory.getInstance();
    final List<VisibilityStatement> statements = new ArrayList<>();
    statements.add( new VisibilityStatement(vf.createStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:talksTo"), vf.createIRI("urn:Bob")), "a") );

    // Show the correct binding set results from the job.
    final Set<VisibilityBindingSet> expected = new HashSet<>();

    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("person", vf.createIRI("urn:Alice"));
    bs.addBinding("otherPerson", vf.createIRI("urn:Bob"));
    expected.add( new VisibilityBindingSet(bs, "a") );

    // Run the test.
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
 
Example 9
Source File: TestFixtures.java    From inception with Apache License 2.0 5 votes vote down vote up
public KBStatement buildStatement(KBHandle conceptHandle, KBProperty aProperty, String value)
{
    ValueFactory vf = SimpleValueFactory.getInstance();
    KBStatement statement = new KBStatement(null, conceptHandle, aProperty,
            vf.createLiteral(value));
    return statement;
}
 
Example 10
Source File: GeoIndexerTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteSearch() throws Exception {
    // test a ring around dc
    try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
        f.setConf(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();

        f.deleteStatement(convertStatement(statement));

        // test a ring that the point would be inside of if not deleted
        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[] {});
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));

        // test a ring that the point would be outside of if not deleted
        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[] {});
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));

        // test a ring for the whole world and make sure the point is gone
        // Geomesa is a little sensitive around lon 180, so we only go to 179
        final double[] world = { -180, 90, 179, 90, 179, -90, -180, -90, -180, 90 };
        final LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2));
        final Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {});
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS)));
    }
}
 
Example 11
Source File: BulkedExternalInnerJoinTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void gapInResultsFromQueryTest() {

	SimpleValueFactory vf = SimpleValueFactory.getInstance();
	IRI a = vf.createIRI("http://a");
	IRI b = vf.createIRI("http://b");
	IRI c = vf.createIRI("http://c");
	IRI d = vf.createIRI("http://d");

	PlanNode left = new MockInputPlanNode(
			Arrays.asList(new Tuple(Collections.singletonList(a)), new Tuple(Collections.singletonList(b)),
					new Tuple(Collections.singletonList(c)), new Tuple(Collections.singletonList(d))));

	MemoryStore sailRepository = new MemoryStore();
	sailRepository.init();

	try (SailConnection connection = sailRepository.getConnection()) {
		connection.begin();
		connection.addStatement(b, DCAT.ACCESS_URL, RDFS.RESOURCE);
		connection.addStatement(d, DCAT.ACCESS_URL, RDFS.SUBPROPERTYOF);
		connection.commit();
	}
	try (SailConnection connection = sailRepository.getConnection()) {

		BulkedExternalInnerJoin bulkedExternalInnerJoin = new BulkedExternalInnerJoin(left, connection,
				"?a <http://www.w3.org/ns/dcat#accessURL> ?c. ", false, null, "?a", "?c");

		List<Tuple> tuples = new MockConsumePlanNode(bulkedExternalInnerJoin).asList();

		tuples.forEach(System.out::println);

		assertEquals("[http://b, http://www.w3.org/2000/01/rdf-schema#Resource]",
				Arrays.toString(tuples.get(0).line.toArray()));
		assertEquals("[http://d, http://www.w3.org/2000/01/rdf-schema#subPropertyOf]",
				Arrays.toString(tuples.get(1).line.toArray()));

	}
}
 
Example 12
Source File: CostFedRepositoryFactory.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Resource export(Model model) {
    Resource implNode = super.export(model);
    SimpleValueFactory vf = SimpleValueFactory.getInstance();

    if (configFileName != null) {
        model.add(implNode, FILENAME, vf.createLiteral(configFileName));
    }

    return implNode;
}
 
Example 13
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 14
Source File: SES2154SubselectOptionalTest.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Test
public void testSES2154SubselectOptional() throws Exception {
    HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "SES2154SubselectOptionaltable", true, 0, true, 0, null, null);
    SailRepository rep = new SailRepository(sail);
    rep.initialize();
    SimpleValueFactory vf = SimpleValueFactory.getInstance();
    IRI person = vf.createIRI("http://schema.org/Person");
    for (char c = 'a'; c < 'k'; c++) {
        sail.addStatement(vf.createIRI("http://example.com/" + c), RDF.TYPE, person);
    }
    sail.commit();
    TupleQueryResult res = rep.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, "PREFIX : <http://example.com/>\n" + "PREFIX schema: <http://schema.org/>\n" + "\n" + "SELECT (COUNT(*) AS ?count)\n" + "WHERE {\n" + "  {\n" + "    SELECT ?person\n" + "    WHERE {\n" + "      ?person a schema:Person .\n" + "    }\n" + "    LIMIT 5\n" + "  }\n" + "  OPTIONAL {\n" + "    [] :nonexistent [] .\n" + "  }\n" + "}").evaluate();
    assertEquals(5, ((Literal) res.next().getBinding("count").getValue()).intValue());
    rep.shutDown();
}
 
Example 15
Source File: TestModelGenerator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TestModelGenerator(ModelFactory factory) {
	super();
	this.mf = factory;
	this.vf = SimpleValueFactory.getInstance();
	this.st0 = vf.createStatement(vf.createIRI("foo:s0"), vf.createIRI("foo:p0"), vf.createIRI("foo:o0"));
	this.st1 = vf.createStatement(vf.createIRI("foo:s1"), vf.createIRI("foo:p1"), vf.createIRI("foo:o1"));
	this.st2 = vf.createStatement(vf.createIRI("foo:s2"), vf.createIRI("foo:p2"), vf.createIRI("foo:o2"));
	this.st3 = vf.createStatement(vf.createIRI("foo:s3"), vf.createIRI("foo:p3"), vf.createIRI("foo:o3"));
	this.st4 = vf.createStatement(vf.createIRI("foo:s4"), vf.createIRI("foo:p4"), vf.createIRI("foo:o4"));
}
 
Example 16
Source File: TestTupleResultBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public final void testSES1846regression() throws Exception {
	TupleResultBuilder builder = new TupleResultBuilder(new SPARQLBooleanXMLWriter(new ByteArrayOutputStream()),
			SimpleValueFactory.getInstance());
	try {
		builder.start();
		builder.bool(true);
		fail("Did not receive expected exception for calling bool after start");
	} catch (QueryResultHandlerException qrhe) {
		// Expected exception
	}
}
 
Example 17
Source File: JSONLDInternalTripleCallbackTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void triplesTest() throws JsonLdError, IOException {
	// String inputstring =
	// "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone
	// Device\"}}";
	final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
	final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
	final Object input = JsonUtils.fromString(inputstring);

	final Model graph = new LinkedHashModel();
	final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
	final ParserConfig parserConfig = new ParserConfig();
	final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(new StatementCollector(graph),
			SimpleValueFactory.getInstance(), parserConfig, parseErrorListener,
			nodeID -> SimpleValueFactory.getInstance().createBNode(nodeID),
			() -> SimpleValueFactory.getInstance().createBNode());

	JsonLdProcessor.toRDF(input, callback);

	final Iterator<Statement> statements = graph.iterator();

	// contains only one statement (type)
	while (statements.hasNext()) {
		final Statement stmt = statements.next();

		System.out.println(stmt.toString());
		assertEquals("Output was not as expected", stmt.toString(), expectedString);
	}

	assertEquals(0, parseErrorListener.getFatalErrors().size());
	assertEquals(0, parseErrorListener.getErrors().size());
	assertEquals(0, parseErrorListener.getWarnings().size());
}
 
Example 18
Source File: AbstractSailTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setUp() throws Exception {

	subject = new AbstractSail() {

		@Override
		public boolean isWritable() throws SailException {
			return false;
		}

		@Override
		public ValueFactory getValueFactory() {
			return SimpleValueFactory.getInstance();
		}

		@Override
		protected void shutDownInternal() throws SailException {
			// TODO Auto-generated method stub

		}

		@Override
		protected SailConnection getConnectionInternal() throws SailException {
			SailConnection connDouble = mock(SailConnection.class);
			doAnswer(f -> {
				subject.connectionClosed(connDouble);
				return null;
			}).when(connDouble).close();
			return connDouble;
		}

	};
}
 
Example 19
Source File: FairConfig.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public SimpleValueFactory simpleValueFactory() {
  return SimpleValueFactory.getInstance();
}
 
Example 20
Source File: SailIsolationLevelTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void testLargeTransaction(IsolationLevel isolationLevel, int count) throws InterruptedException {

		try (SailConnection connection = store.getConnection()) {
			connection.begin(IsolationLevels.NONE);
			connection.clear();
			connection.commit();
		}

		AtomicBoolean failure = new AtomicBoolean(false);

		Runnable runnable = () -> {

			try (SailConnection connection = store.getConnection()) {
				while (true) {
					try {
						connection.begin(isolationLevel);
						List<Statement> statements = Iterations
								.asList(connection.getStatements(null, null, null, false));
						connection.commit();
						if (statements.size() != 0) {
							if (statements.size() != count) {
								logger.error("Size was {}. Expected 0 or {}", statements.size(), count);
								logger.error("\n[\n\t{}\n]",
										statements.stream()
												.map(Object::toString)
												.reduce((a, b) -> a + " , \n\t" + b)
												.get());

								failure.set(true);
							}
							break;
						}
					} catch (SailConflictException ignored) {
						connection.rollback();
					}

					Thread.yield();
				}
			}
		};

		Thread thread = new Thread(runnable);
		thread.start();

		SimpleValueFactory vf = SimpleValueFactory.getInstance();

		try (SailConnection connection = store.getConnection()) {
			connection.begin(isolationLevel);
			for (int i = 0; i < count; i++) {
				connection.addStatement(RDFS.RESOURCE, RDFS.LABEL, vf.createLiteral(i));
			}
			logger.debug("Commit");
			connection.commit();

			assertEquals(count, connection.size());

		}

		logger.debug("Joining thread");
		thread.join();

		assertFalse(failure.get());

	}