本文整理匯總了Java中org.openrdf.model.ValueFactory.createBNode方法的典型用法代碼示例。如果您正苦於以下問題:Java ValueFactory.createBNode方法的具體用法?Java ValueFactory.createBNode怎麽用?Java ValueFactory.createBNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.model.ValueFactory
的用法示例。
在下文中一共展示了ValueFactory.createBNode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cleanValue
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
/**
* "Cleans" a value for BigData
*
* @param v the value that needs cleaning
* @param vf the value factory to make the new Value from
* @return a value that won't make BigData bomb
*/
public static Value cleanValue( Value v, ValueFactory vf ) {
Value newv;
if ( v instanceof URI ) {
newv = vf.createURI( v.stringValue() );
}
else if ( v instanceof BNode ) {
newv = vf.createBNode( v.stringValue() );
}
else {
Literal oldv = Literal.class.cast( v );
if ( null != oldv.getLanguage() ) {
newv = vf.createLiteral( oldv.stringValue(), oldv.getLanguage() );
}
else {
newv = vf.createLiteral( oldv.stringValue(), oldv.getDatatype() );
}
}
return newv;
}
示例2: bnode
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
/**
* BNode factory
*
* @return
*/
public BNode bnode() {
try {
RepositoryConnection con = therepository.getConnection();
try {
ValueFactory vf = con.getValueFactory();
return vf.createBNode();
} finally {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例3: hasValueFromList
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
private void hasValueFromList() {
ValueFactory vf = getValueFactory();
for (Statement st : ds.match(null, OWL.HASVALUE, null)) {
Resource res = st.getSubject();
Value obj = st.getObject();
if (obj instanceof Resource) {
BNode node = vf.createBNode();
ds.add(res, OWL.ALLVALUESFROM, node);
ds.add(node, RDF.TYPE, OWL.CLASS);
BNode list = vf.createBNode();
ds.add(node, OWL.ONEOF, list);
ds.add(list, RDF.TYPE, RDF.LIST);
ds.add(list, RDF.FIRST, obj);
ds.add(list, RDF.REST, RDF.NIL);
for (Value type : ds.match(obj, RDF.TYPE, null).objects()) {
ds.add(node, RDFS.SUBCLASSOF, type);
}
for (Value prop : ds.match(res, OWL.ONPROPERTY, null).objects()) {
for (Value range : ds.match(prop, RDFS.RANGE, null).objects()) {
ds.add(node, RDFS.SUBCLASSOF, range);
}
for (Resource cls : ds.match(null, RDFS.SUBCLASSOF, res).subjects()) {
for (Value sup : findSuperClasses(cls)) {
if (!sup.equals(res) && !ds.match(sup, OWL.ONPROPERTY, prop).isEmpty()) {
for (Value from : ds.match(sup, OWL.ALLVALUESFROM, null).objects()) {
ds.add(node, RDFS.SUBCLASSOF, from);
}
}
}
}
}
}
}
}
示例4: getSesameResource
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
public static org.openrdf.model.Resource getSesameResource(SubjectNode subject, ValueFactory valueFactory) {
if (subject instanceof BlankNode) {
return valueFactory.createBNode("" + subject.hashCode());
}
else { // must be a URIReference
return getSesameURI((URIReference) subject, valueFactory);
}
}
示例5: getSesameValue
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
public static org.openrdf.model.Value getSesameValue(Node object, ValueFactory valueFactory) {
if (object instanceof BlankNode) {
return valueFactory.createBNode(String.valueOf(object.hashCode()));
}
else if (object instanceof URIReference) {
return getSesameURI((URIReference) object, valueFactory);
}
else { // must be a Literal
return getSesameLiteral((Literal) object, valueFactory);
}
}
示例6: copyFromTdb
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
private void copyFromTdb( Dataset dataset ) throws RepositoryException {
ValueFactory vf = rc.getValueFactory();
if ( dataset.supportsTransactions() ) {
dataset.begin( ReadWrite.READ );
}
// Get model inside the transaction
Model model = dataset.getDefaultModel();
StmtIterator si = model.listStatements();
try {
rc.begin();
while ( si.hasNext() ) {
Statement stmt = si.next();
com.hp.hpl.jena.rdf.model.Resource rsr = stmt.getSubject();
Property pred = stmt.getPredicate();
RDFNode val = stmt.getObject();
Node valnode = val.asNode();
Resource sub;
try {
sub = ( rsr.isAnon()
? vf.createBNode( valnode.getBlankNodeLabel() )
: vf.createURI( rsr.toString() ) );
}
catch ( UnsupportedOperationException uoo ) {
log.warn( uoo, uoo );
continue;
}
URI pred2 = vf.createURI( pred.toString() );
Value val2;
if ( val.isLiteral() ) {
Literal lit = val.asLiteral();
String dtstr = lit.getDatatypeURI();
URI dt = ( null == dtstr ? null : vf.createURI( dtstr ) );
String langstr = lit.getLanguage();
if ( null == dt ) {
if ( langstr.isEmpty() ) {
val2 = vf.createLiteral( lit.toString() );
}
else {
val2 = vf.createLiteral( lit.toString(), langstr );
}
}
else {
val2 = vf.createLiteral( lit.toString(), dt );
}
}
else {
if ( val.isAnon() ) {
val2 = vf.createBNode( valnode.getBlankNodeLabel() );
}
else {
val2 = vf.createURI( val.toString() );
}
}
rc.add( sub, pred2, val2 );
}
rc.commit();
}
catch ( RepositoryException re ) {
rc.rollback();
throw re;
}
finally {
if ( dataset.supportsTransactions() ) {
dataset.end();
}
}
}
示例7: serializeValueComposite
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
private void serializeValueComposite( Resource subject, URI predicate,
ValueComposite value,
ValueType valueType,
Graph graph,
String baseUri,
boolean includeNonQueryable
)
{
final ValueFactory valueFactory = graph.getValueFactory();
BNode collection = valueFactory.createBNode();
graph.add( subject, predicate, collection );
( (ValueCompositeType) valueType ).properties().forEach(
persistentProperty ->
{
Object propertyValue
= PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF
.apply( value )
.state()
.propertyFor( persistentProperty.accessor() )
.get();
if( propertyValue != null )
{
ValueType type = persistentProperty
.valueType();
if( type instanceof ValueCompositeType )
{
URI pred = valueFactory.createURI( baseUri,
persistentProperty
.qualifiedName()
.name() );
serializeValueComposite( collection, pred,
(ValueComposite) propertyValue,
type, graph,
baseUri
+ persistentProperty
.qualifiedName()
.name() + "/",
includeNonQueryable );
}
else
{
serializeProperty( persistentProperty,
propertyValue,
collection, graph,
includeNonQueryable );
}
}
} );
}
示例8: showProcessorWorks
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void showProcessorWorks() 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(queryId);
// Create a topology for the Query that will be tested.
final String sparql =
"CONSTRUCT {" +
"_:b a <urn:movementObservation> ; " +
"<urn:location> ?location ; " +
"<urn:direction> ?direction ; " +
"}" +
"WHERE {" +
"?thing <urn:corner> ?location ." +
"?thing <urn:compass> ?direction." +
"}";
final String bNodeId = UUID.randomUUID().toString();
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, () -> bNodeId);
// Create the statements that will be input into the query.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = new ArrayList<>();
statements.add( new VisibilityStatement(
vf.createStatement(vf.createURI("urn:car1"), vf.createURI("urn:compass"), vf.createURI("urn:NW")), "a") );
statements.add( new VisibilityStatement(
vf.createStatement(vf.createURI("urn:car1"), vf.createURI("urn:corner"), vf.createURI("urn:corner1")), "a") );
// Make the expected results.
final Set<VisibilityStatement> expected = new HashSet<>();
final BNode blankNode = vf.createBNode(bNodeId);
expected.add(new VisibilityStatement(vf.createStatement(blankNode, RDF.TYPE, vf.createURI("urn:movementObservation")), "a"));
expected.add(new VisibilityStatement(vf.createStatement(blankNode, vf.createURI("urn:direction"), vf.createURI("urn:NW")), "a"));
expected.add(new VisibilityStatement(vf.createStatement(blankNode, vf.createURI("urn:location"), vf.createURI("urn:corner1")), "a"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityStatementDeserializer.class);
}
示例9: read
import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Nullable
private static Value read(final String[] nsArray, final ByteArrayInputStream stream) {
try {
final ValueFactory vf = Statements.VALUE_FACTORY;
final int b = stream.read();
final int hi = b & 0xE0;
if (hi == HI_NULL) {
return null;
} else if (hi == HI_BNODE) {
final byte[] id = new byte[(b & 0x1F) << 8 | stream.read()];
ByteStreams.readFully(stream, id);
return vf.createBNode(new String(id, Charsets.UTF_8));
} else if (hi == HI_URI) {
if ((b & 0x10) != 0) {
final byte[] name = new byte[(b & 0xF) << 8 | stream.read()];
final String ns = nsArray[stream.read()];
ByteStreams.readFully(stream, name);
return vf.createURI(ns, new String(name, Charsets.UTF_8));
} else {
final byte[] str = new byte[(b & 0xF) << 8 | stream.read()];
ByteStreams.readFully(stream, str);
return vf.createURI(new String(str, Charsets.UTF_8));
}
} else if (hi == HI_LITERAL) {
byte[] lang = null;
URI dt = null;
if ((b & 0x10) != 0) {
lang = new byte[b & 0xF];
ByteStreams.readFully(stream, lang);
} else if ((b & 0x1) != 0) {
dt = DT_MAP.inverse().get(stream.read());
} else if ((b & 0x2) != 0) {
dt = (URI) read(nsArray, stream);
}
final byte[] label = new byte[stream.read() << 16 | stream.read() << 8
| stream.read()];
ByteStreams.readFully(stream, label);
final String labelStr = new String(label, Charsets.UTF_8);
if (lang != null) {
return vf.createLiteral(labelStr, new String(lang, Charsets.UTF_8));
} else if (dt != null) {
return vf.createLiteral(labelStr, dt);
} else {
return vf.createLiteral(labelStr);
}
} else {
throw new Error("Invalid marker: " + b);
}
} catch (final IOException ex) {
throw new Error(ex);
}
}