本文整理匯總了Java中org.openrdf.model.ValueFactory.createStatement方法的典型用法代碼示例。如果您正苦於以下問題:Java ValueFactory.createStatement方法的具體用法?Java ValueFactory.createStatement怎麽用?Java ValueFactory.createStatement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.model.ValueFactory
的用法示例。
在下文中一共展示了ValueFactory.createStatement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: matchesSubject
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void matchesSubject() throws Exception {
// Create the matcher against a pattern that matches a specific subject.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"<urn:Alice> ?p ?o ." +
"}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("p", vf.createURI("urn:talksTo"));
expected.addBinding("o", vf.createURI("urn:Bob"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
示例2: doesNotMatchSubject
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void doesNotMatchSubject() throws Exception {
// Create the matcher against a pattern that matches a specific subject.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"<urn:Alice> ?p ?o ." +
"}"));
// Create a statement that does not match the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Show the statement did not match.
final Optional<BindingSet> bs = matcher.match(statement);
assertFalse(bs.isPresent());
}
示例3: matchesPredicate
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void matchesPredicate() throws Exception {
// Create the matcher against a pattern that matches a specific predicate.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"?s <urn:talksTo> ?o ." +
"}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("o", vf.createURI("urn:Bob"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
示例4: doesNotMatchPredicate
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void doesNotMatchPredicate() throws Exception {
// Create the matcher against a pattern that matches a specific predicate.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"?s <urn:talksTo> ?o ." +
"}"));
// Create a statement that does not match the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:knows"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Show the statement did not match.
final Optional<BindingSet> bs = matcher.match(statement);
assertFalse(bs.isPresent());
}
示例5: matchesObject
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void matchesObject() throws Exception {
// Create the matcher against a pattern that matches a specific object.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"?s ?p <urn:Bob> ." +
"}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("p", vf.createURI("urn:talksTo"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
示例6: doesNotMatchObject
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void doesNotMatchObject() throws Exception {
// Create the matcher against a pattern that matches a specific object.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"?s ?p <urn:Bob> ." +
"}"));
// Create a statement that does not match the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:knows"), vf.createURI("urn:Alice"), vf.createURI("urn:testGraph"));
// Show the statement did not match.
final Optional<BindingSet> bs = matcher.match(statement);
assertFalse(bs.isPresent());
}
示例7: matchesContext
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void matchesContext() throws Exception {
// Create a matcher against a pattern that matches a specific context.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"GRAPH <urn:testGraph> {" +
"?s ?p ?o ." +
"}" +
"}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("p", vf.createURI("urn:talksTo"));
expected.addBinding("o", vf.createURI("urn:Bob"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
示例8: variableContext
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void variableContext() throws Exception {
// Create a matcher against a pattern that matches a variable context.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp(
"SELECT * WHERE {" +
"GRAPH ?c {" +
"?s ?p ?o ." +
"}" +
"}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("p", vf.createURI("urn:talksTo"));
expected.addBinding("o", vf.createURI("urn:Bob"));
expected.addBinding("c", vf.createURI("urn:testGraph"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
示例9: testAddStatement
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Ignore
@Test
public void testAddStatement() throws Exception {
SailRepositoryFactory f = new SailRepositoryFactory();
Repository r = f.getRepository(getConfig());
r.initialize();
RepositoryConnection rc = r.getConnection();
ValueFactory vf = rc.getValueFactory();
Statement s = vf.createStatement(vf.createURI("u:a"), vf.createURI("u:b"), vf.createURI("u:c"));
assertFalse(rc.hasStatement(s, false));
rc.add(s);
Assert.assertTrue(rc.hasStatement(s, false));
rc.close();
}
示例10: binaryResult
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void binaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new BinaryResult(Side.LEFT, visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(
vf.createURI("urn:Alice"),
vf.createURI("urn:age"),
vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
示例11: testContextSearch
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void testContextSearch() throws Exception {
try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
f.setConf(conf);
f.init();
final ValueFactory vf = new ValueFactoryImpl();
final URI subject = new URIImpl("foo:subj");
final URI predicate = new URIImpl(RDFS.COMMENT.toString());
final Value object = vf.createLiteral("this is a new hat");
final URI context = new URIImpl("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.createURI("foo:context2")))));
}
}
示例12: testContextSearch
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void testContextSearch() throws Exception {
try (AccumuloFreeTextIndexer f = new AccumuloFreeTextIndexer()) {
f.setConf(conf);
f.setMultiTableBatchWriter(ConfigUtils.createMultitableBatchWriter(conf));
f.init();
ValueFactory vf = new ValueFactoryImpl();
URI subject = new URIImpl("foo:subj");
URI predicate = new URIImpl(RDFS.COMMENT.toString());
Value object = vf.createLiteral("this is a new hat");
URI context = new URIImpl("foo:context");
Statement statement = vf.createStatement(subject, predicate, object, context);
f.storeStatement(RdfToRyaConversions.convertStatement(statement));
f.flush();
Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
Assert.assertEquals(Sets.newHashSet(),
getSet(f.queryText("hat", new StatementConstraints().setContext(vf.createURI("foo:context2")))));
}
}
示例13: serializeAndDeserialize
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void serializeAndDeserialize() {
// Create the object that will be serialized.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(
vf.createURI("urn:person1"),
vf.createURI("urn:hasName"),
vf.createLiteral("alice"),
vf.createURI("urn:testContext"));
final VisibilityStatement original = new VisibilityStatement(statement, "a|b|c");
// Serialize it.
try(final Serde<VisibilityStatement> serde = new VisibilityStatementSerde()) {
final byte[] bytes = serde.serializer().serialize("topic", original);
// Deserialize it.
final VisibilityStatement deserialized = serde.deserializer().deserialize("topic", bytes);
// Show the deserialized value matches the original.
assertEquals(original, deserialized);
}
}
示例14: unaryResult
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void unaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(
vf.createURI("urn:Alice"),
vf.createURI("urn:age"),
vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
示例15: add
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
/**
* Insert Triple/Statement into graph
*
* @param s
* subject uriref
* @param p
* predicate uriref
* @param o
* value object (URIref or Literal)
*/
public void add(URI s, URI p, Value o) {
try {
RepositoryConnection con = therepository.getConnection();
try {
ValueFactory myFactory = con.getValueFactory();
Statement st = myFactory.createStatement((Resource) s, p, (Value) o);
con.add(st, new Resource[0]);
} finally {
con.close();
}
} catch (Exception e) {
// handle exception
}
}