本文整理汇总了Java中org.openrdf.model.BNode类的典型用法代码示例。如果您正苦于以下问题:Java BNode类的具体用法?Java BNode怎么用?Java BNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BNode类属于org.openrdf.model包,在下文中一共展示了BNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanValue
import org.openrdf.model.BNode; //导入依赖的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: getDatatype
import org.openrdf.model.BNode; //导入依赖的package包/类
/**
* Gets the datatype of the given val. If val is null, returns null. It
* returns {@link XMLSchema#ANYURI} for a URI, {@link XMLSchema#ENTITY} for a
* BNode, and {@link Literal#getDatatype()} if it's a literal. If it's not a
* {@link Value}, then it is converted to a Value first, and reprocessed. If
* we have a literal, but a null datatype, returns {@link XMLSchema#STRING}
*
* @param val
* @return
*/
public static URI getDatatype( Object val ) {
if ( null == val ) {
return null;
}
if ( val instanceof URI ) {
return XMLSchema.ANYURI;
}
else if ( val instanceof Literal ) {
Literal l = Literal.class.cast( val );
return ( null == l.getDatatype() ? XMLSchema.STRING : l.getDatatype() );
}
else if ( val instanceof BNode ) {
return XMLSchema.ENTITY;
}
Class<?> theClass = val.getClass();
return REVTYPELOOKUP.getOrDefault( theClass, XMLSchema.STRING );
}
示例3: project
import org.openrdf.model.BNode; //导入依赖的package包/类
/**
* Apply the projections against a {@link VisibilityBindingSet}.
*
* @param bs - The value the projection will be applied to. (not null)
* @return A set of values that result from the projection.
*/
public Set<VisibilityBindingSet> project(final VisibilityBindingSet bs) {
requireNonNull(bs);
// Generate an ID for each blank node that will appear in the results.
final Map<String, BNode> blankNodes = new HashMap<>();
for(final String blankNodeSourceName : blankNodeSourceNames) {
blankNodes.put(blankNodeSourceName, vf.createBNode(bNodeIdFactory.nextId()));
}
// Iterate through each of the projections and create the results from them.
final Set<VisibilityBindingSet> results = new HashSet<>();
for(final ProjectionEvaluator projection : projections) {
results.add( projection.project(bs, blankNodes) );
}
return results;
}
示例4: testConstructProjectionBNodes
import org.openrdf.model.BNode; //导入依赖的package包/类
@Test
public void testConstructProjectionBNodes() throws MalformedQueryException {
String query = "select ?o where { _:b <uri:talksTo> ?o }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructProjection projection = new ConstructProjection(patterns.get(0));
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("o", vf.createURI("uri:Bob"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
BNode bNode = vf.createBNode();
Map<String, BNode> bNodeMap = new HashMap<>();
bNodeMap.put("-anon-1", bNode);
RyaStatement statement = projection.projectBindingSet(vBs,bNodeMap);
RyaStatement expected = new RyaStatement(RdfToRyaConversions.convertResource(bNode), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
expected.setTimestamp(statement.getTimestamp());
expected.setColumnVisibility(new byte[0]);
assertEquals(expected, statement);
}
示例5: skolemize
import org.openrdf.model.BNode; //导入依赖的package包/类
private Statement skolemize(final Statement statement) {
boolean skolemized = false;
Resource subj = statement.getSubject();
if (subj instanceof BNode) {
subj = skolemize((BNode) subj);
skolemized = true;
}
Value obj = statement.getObject();
if (obj instanceof BNode) {
obj = skolemize((BNode) obj);
skolemized = true;
}
if (skolemized) {
final URI pred = statement.getPredicate();
return Data.getValueFactory().createStatement(subj, pred, obj);
}
return statement;
}
示例6: emit
import org.openrdf.model.BNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Rendering emit(final Object value) {
if (value instanceof String) {
return emit((String) value);
} else if (value instanceof QueryModelNode) {
emit((QueryModelNode) value);
} else if (value instanceof BNode) {
emit((BNode) value);
} else if (value instanceof URI) {
emit((URI) value);
} else if (value instanceof Literal) {
emit((Literal) value);
} else if (value instanceof List<?>) {
emit((List<StatementPattern>) value);
} else if (value instanceof Query) {
emit((Query) value);
}
return this;
}
示例7: writeValue
import org.openrdf.model.BNode; //导入依赖的package包/类
private void writeValue(Value value) throws IOException {
if (value instanceof Literal) {
//Literal l = (Literal) value;
//if (l.getLanguage() != null)
//{
// if (l.getLanguage().equals(languageTag)) {
// jsonWriter.value(value.stringValue());
// }
//} else {
jsonWriter.value(value.stringValue());
//}
} else if (value instanceof BNode) {
jsonWriter.value(resourceToString((BNode) value));
} else if (value instanceof URI) {
jsonWriter.value(resourceToString((URI) value));
}
}
示例8: writePredicateStatToVoid
import org.openrdf.model.BNode; //导入依赖的package包/类
private void writePredicateStatToVoid(URI dataset, URI predicate, long pCount, int distS, int distO) {
BNode propPartition = vf.createBNode();
Literal count = vf.createLiteral(String.valueOf(pCount));
Literal distinctS = vf.createLiteral(String.valueOf(distS));
Literal distinctO = vf.createLiteral(String.valueOf(distO));
try {
writer.handleStatement(vf.createStatement(dataset, vf.createURI(VOID2.propertyPartition.toString()), propPartition));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.property.toString()), predicate));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.triples.toString()), count));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.distinctSubjects.toString()), distinctS));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.distinctObjects.toString()), distinctO));
} catch (RDFHandlerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例9: writePredicateStatToVoid
import org.openrdf.model.BNode; //导入依赖的package包/类
private void writePredicateStatToVoid(URI predicate, long pCount, int distS, int distO) {
BNode propPartition = vf.createBNode();
Literal count = vf.createLiteral(String.valueOf(pCount));
Literal distinctS = vf.createLiteral(String.valueOf(distS));
Literal distinctO = vf.createLiteral(String.valueOf(distO));
try {
writer.handleStatement(vf.createStatement(dataset, vf.createURI(VOID2.propertyPartition.toString()), propPartition));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.property.toString()), predicate));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.triples.toString()), count));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.distinctSubjects.toString()), distinctS));
writer.handleStatement(vf.createStatement(propPartition, vf.createURI(VOID2.distinctObjects.toString()), distinctO));
} catch (RDFHandlerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: makeNewHashID
import org.openrdf.model.BNode; //导入依赖的package包/类
/**
* Creates a new (hash) identifier for the given resource.
*
* @param node the resource.
* @param n3 the N3 representation of the resource.
* @return a new (hash) identifier for the given resource.
*/
private static byte[] makeNewHashID(final Value node, final String n3) {
final byte[] hash = Utility.murmurHash3(n3.getBytes(CHARSET_UTF8)).asBytes();
final ByteBuffer buffer = ByteBuffer.allocate(ID_LENGTH);
if (node instanceof Literal) {
buffer.put(LITERAL_BYTE_FLAG);
} else if (node instanceof BNode) {
buffer.put(BNODE_BYTE_FLAG);
} else {
buffer.put(RESOURCE_BYTE_FLAG);
}
buffer.put(hash);
buffer.flip();
return buffer.array();
}
示例11: load
import org.openrdf.model.BNode; //导入依赖的package包/类
/**
* Loads data associated with this blank node.
*/
private synchronized void load() {
if (_has_data) {
return;
}
// load data ...
try {
final BNode bnode = (BNode) _dict.getValue(_internalID, false);
super.setID(bnode.getID());
} catch (final Exception exception) {
_log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID));
super.setID("cumulus/internal/" + Arrays.toString(_internalID));
}
_has_data = true;
}
示例12: hash
import org.openrdf.model.BNode; //导入依赖的package包/类
private URI hash(final Resource subject, final URI predicate, final Value object) {
final List<String> list = Lists.newArrayList();
for (final Value value : new Value[] { subject, predicate, object }) {
if (value instanceof URI) {
list.add("\u0001");
list.add(value.stringValue());
} else if (value instanceof BNode) {
list.add("\u0002");
list.add(((BNode) value).getID());
} else if (value instanceof Literal) {
final Literal l = (Literal) value;
list.add("\u0003");
list.add(l.getLabel());
if (l.getDatatype() != null) {
list.add(l.getDatatype().stringValue());
} else if (l.getLanguage() != null) {
list.add(l.getLanguage());
}
}
}
final String id = Hash.murmur3(list.toArray(new String[list.size()])).toString();
return FACTORY.createURI("fact:" + id);
}
示例13: writeSubject
import org.openrdf.model.BNode; //导入依赖的package包/类
private void writeSubject(final Resource subject, final Multimap<URI, Value> properties)
throws IOException
{
this.writer.writeEOL();
if (!(subject instanceof BNode) || this.bnodePreservationPolicy.apply((BNode) subject)
|| this.objectBNodes.containsKey(subject)) {
writeResource(subject);
this.writer.write(" ");
} else {
this.writer.write("[] ");
}
this.writer.increaseIndentation();
writeProperties(properties);
this.writer.write(" .");
this.writer.decreaseIndentation();
}
示例14: writeDesc
import org.openrdf.model.BNode; //导入依赖的package包/类
/**
* Adds to the description table information for a binding.
*
* @param binding
*/
protected void writeDesc(Binding binding) {
descData.append(NEWLINE);
indent(descData, depth + 1);
descData.append(TABLE_ROW_BEGIN);
descData.append(TABLE_DATA_BEGIN);
descData.append(binding.getName());
descData.append(TABLE_DATA_END);
descData.append(TABLE_DATA_BEGIN);
if (binding.getValue() instanceof BNode) {
descData.append("_:");
}
descData.append(binding.getValue().stringValue());
descData.append(TABLE_DATA_END);
descData.append(TABLE_ROW_END);
}
示例15: addEPCsToGraph
import org.openrdf.model.BNode; //导入依赖的package包/类
/**
* @param ns
* @param mySubject
* @param myGraph
* @param epcArray
*/
public Graph addEPCsToGraph(Namespaces ns, Graph myGraph, URI mySubject,
ArrayList<String> epcArray) {
if (epcArray.size() > 0) {
ValueFactory myFactory = ValueFactoryImpl.getInstance();
BNode bnodeEPC = myFactory.createBNode();
// link the EPCS to the event
myGraph.add(mySubject, myFactory.createURI(
ns.getIRIForPrefix("eem"), "associatedWithEPCList"),
bnodeEPC);
myGraph.add(bnodeEPC, RDF.TYPE,
myFactory.createURI(ns.getIRIForPrefix("eem"), "SetOfEPCs"));
for (String e : epcArray) {
myGraph.add(bnodeEPC,
myFactory.createURI("http://purl.org/co#element"),
myFactory.createURI(e.trim()));
// System.out.println(e);
}
}
return myGraph;
}