org.openrdf.model.BNode Java Examples

The following examples show how to use org.openrdf.model.BNode. 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: NativeCumulusBNode.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: TestStandaloneRDRParsers.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void testStandaloneParser(RDFParser parser, String resourceName) throws IOException,
		RDFParseException, RDFHandlerException {
	bNodeFound = false;
	parser.setRDFHandler(new RDFHandlerBase(){
		@Override
		public void handleStatement(Statement st)
				throws RDFHandlerException {
			if (st.getSubject() instanceof BNode) {
				bNodeFound = true;
			}
			super.handleStatement(st);
		}
	});
	try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourceName)) {
		parser.parse(is, "");
	}
	assertTrue(bNodeFound);
}
 
Example #3
Source File: ComplexSPARQLQueryTest.java    From database with GNU General Public License v2.0 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();
	URI b = f.createURI("http://example.org/b");
	URI p = f.createURI("http://example.org/p");
	Model result = QueryResults.asModel(gq.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: PersistentValueDictionary.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: ComplexSPARQLQueryTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDescribeAWhere()
	throws Exception
{
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ?x WHERE {?x rdfs:label \"a\". } ");

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

	ValueFactory f = conn.getValueFactory();
	URI a = f.createURI("http://example.org/a");
	URI p = f.createURI("http://example.org/p");
	Model result = QueryResults.asModel(gq.evaluate());
	Set<Value> objects = result.filter(a, p, null).objects();
	assertNotNull(objects);
	for (Value object : objects) {
		if (object instanceof BNode) {
			assertTrue(result.contains((Resource)object, null, null));
			assertEquals(2, result.filter((Resource)object, null, null).size());
		}
	}
}
 
Example #6
Source File: ComplexSPARQLQueryTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDescribeA()
	throws Exception
{
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:a");

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

	ValueFactory f = conn.getValueFactory();
	URI a = f.createURI("http://example.org/a");
	URI p = f.createURI("http://example.org/p");
	Model result = QueryResults.asModel(gq.evaluate());
	Set<Value> objects = result.filter(a, p, null).objects();
	assertNotNull(objects);
	for (Value object : objects) {
		if (object instanceof BNode) {
			assertTrue(result.contains((Resource)object, null, null));
			assertEquals(2, result.filter((Resource)object, null, null).size());
		}
	}
}
 
Example #7
Source File: RDFStoreTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBNodeReuse()
	throws Exception
{
	con.begin();
	con.addStatement(RDF.VALUE, RDF.VALUE, RDF.VALUE);
	assertEquals(1, con.size());
	BNode b1 = vf.createBNode();
	con.addStatement(b1, RDF.VALUE, b1);
	con.removeStatements(b1, RDF.VALUE, b1);
	assertEquals(1, con.size());
	BNode b2 = vf.createBNode();
	con.addStatement(b2, RDF.VALUE, b2);
	con.addStatement(b1, RDF.VALUE, b1);
	assertEquals(3, con.size());
	con.commit();
}
 
Example #8
Source File: BigdataGraphEmbedded.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Changed events coming from bigdata.
 */
@Override
public void changeEvent(final IChangeRecord record) {
    /*
     * Watch out for history change events.
     */
    if (record.getStatement().getSubject() instanceof BNode) {
        return;
    }
    /*
     * Adds come in already materialized. Removes do not. Batch and
     * materialize at commit or abort notification.
     */
    if (record.getChangeAction() == ChangeAction.REMOVED) {
        synchronized(removes) {
            removes.add(record);
        }
    } else {
        notify(record);
    }
}
 
Example #9
Source File: ModelUtil.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private static boolean matchModels(Set<? extends Statement> model1, Set<? extends Statement> model2) {
	// Compare statements without blank nodes first, save the rest for later
	List<Statement> model1BNodes = new ArrayList<Statement>(model1.size());

	for (Statement st : model1) {
		if (st.getSubject() instanceof BNode || st.getObject() instanceof BNode) {
			model1BNodes.add(st);
		}
		else {
			if (!model2.contains(st)) {
				return false;
			}
		}
	}

	return matchModels(model1BNodes, model2, new HashMap<BNode, BNode>(), 0);
}
 
Example #10
Source File: RemoteSparqlBuilderFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return <code>true</code> iff (a) there is more than one solution; and (b)
 * any of the solutions has a blank node which is bound for more than one
 * variable. We need to use a different strategy for vectoring the solutions
 * to the remote service when this is true.
 * 
 * @param bindingSets
 *            The solutions.
 */
static private boolean hasCorrelatedBlankNodeBindings(
        final BindingSet[] bindingSets) {
    
    if (bindingSets.length <= 1) {
        /*
         * Correlation in the variables through shared blank nodes is Ok as
         * long as there is only one solution flowing into the service end
         * point.
         */
        return false;
    }
    
    for (BindingSet bindingSet : bindingSets) {
        Set<BNode> bnodes = null;
        for (Binding b : bindingSet) {
            final Value v = b.getValue();
            if (!(v instanceof BNode))
                continue;
            if (bnodes == null)
                bnodes = new HashSet<BNode>();
            final BNode t = (BNode) v;
            if (bnodes.add(t)) {
                /*
                 * This solution has at least two variable bindings for the
                 * same blank node.
                 */
                return true;
            }
        }
    }
 
    /*
     * No solution has two or more variables which are bound in that
     * solution to the same blank node.
     */
    return false;
    
}
 
Example #11
Source File: ConversionUtil.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts an OpenRDF Value instance into its corresponding RDF2Go
 * representation.
 * 
 * @param value The Value to transform.
 * @return An instance of an RDF2Go data type representing the specified
 *         Value. Returns 'null' when the Value is null.
 * @throws IllegalArgumentException when the specified Value is of an
 *             unrecognized type.
 */
public static Node toRdf2go(Value value) {
	if(value == null) {
		return null;
	} else if(value instanceof org.openrdf.model.URI) {
		return toRdf2go((org.openrdf.model.URI)value);
	} else if(value instanceof org.openrdf.model.Literal) {
		return toRdf2go((org.openrdf.model.Literal)value);
	} else if(value instanceof BNode) {
		return toRdf2go((BNode)value);
	} else {
		throw new IllegalArgumentException("Unexpected Value type: "
		        + value.getClass().getName());
	}
}
 
Example #12
Source File: UpdateExprBuilder.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private boolean isInvalidBlankNode(Value v) {
	if (v instanceof BigdataBNode && ((BigdataBNode)v).isStatementIdentifier()) {
		return false;
	} else {
		return v instanceof BNode;
	}
}
 
Example #13
Source File: ModelUtil.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private static List<Statement> findMatchingStatements(Statement st, Iterable<? extends Statement> model,
		Map<BNode, BNode> bNodeMapping)
{
	List<Statement> result = new ArrayList<Statement>();

	for (Statement modelSt : model) {
		if (statementsMatch(st, modelSt, bNodeMapping)) {
			// All components possibly match
			result.add(modelSt);
		}
	}

	return result;
}
 
Example #14
Source File: RepositoryConnectionTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testBNodeSerialization()
	throws Exception
{
	testCon.add(bob, name, nameBob);

	Statement st;
	RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, false);
	try {
		st = statements.next();
	}
	finally {
		statements.close();
	}

	BNode bnode = (BNode)st.getSubject();

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream out = new ObjectOutputStream(baos);
	out.writeObject(bnode);
	out.close();

	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	ObjectInputStream in = new ObjectInputStream(bais);
	BNode deserializedBNode = (BNode)in.readObject();
	in.close();

	assertThat(deserializedBNode, is(equalTo(bnode)));

	assertThat(testCon.hasStatement(bnode, name, nameBob, true), is(equalTo(true)));
	assertThat(testCon.hasStatement(deserializedBNode, name, nameBob, true), is(equalTo(true)));
}
 
Example #15
Source File: ComplexSPARQLQueryTest.java    From database with GNU General Public License v2.0 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();
	URI f = vf.createURI("http://example.org/f");
	URI p = vf.createURI("http://example.org/p");
	Model result = QueryResults.asModel(gq.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 #16
Source File: ConnectionRecorder.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private void print(Object object) {
	if (object instanceof Object[]) {
		out.print("new ");
		out.print(object.getClass().getComponentType().getSimpleName());
		out.print("[]{");
		Object[] ar = (Object[]) object;
		for (int i=0; i<ar.length; i++) {
			if (i > 0) {
				out.print(",");
			}
			print(ar[i]);
		}
		out.print("}");
	} else if (object instanceof URI) {
		out.print("new URIImpl(\"");
		out.print(object);
		out.print("\")");
	} else if (object instanceof BNode) {
		BNode bnode = (BNode) object;
		out.print("new BNodeImpl(\"");
		out.print(bnode.getID());
		out.print("\")");
	} else if (object instanceof Literal) {
		Literal lit = (Literal) object;
		out.print("new LiteralImpl(");
		out.print(lit.toString());
		out.print(")");
	} else {
		out.print(object);
	}
}
 
Example #17
Source File: ComplexSPARQLQueryTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testDescribeD()
	throws Exception
{
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:d");

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

	ValueFactory f = conn.getValueFactory();
	URI d = f.createURI("http://example.org/d");
	URI p = f.createURI("http://example.org/p");
	URI e = f.createURI("http://example.org/e");
	Model result = QueryResults.asModel(gq.evaluate());

	assertNotNull(result);
	assertTrue(result.contains(null, p, e));
	assertFalse(result.contains(e, null, null));
	Set<Value> objects = result.filter(d, 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 #18
Source File: SesameModelParser.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
public Node parseValue(Value object) {
	Node result=null;
	if(object instanceof org.openrdf.model.URI) {
		result=parseURI((org.openrdf.model.URI)object);
	} else if(object instanceof org.openrdf.model.BNode) {
		result=parseBlankNode((org.openrdf.model.BNode)object);
	} else if(object instanceof org.openrdf.model.Literal) {
		result=parseLiteral((org.openrdf.model.Literal)object);
	} else {
		throw new AssertionError("Unexpected value type '"+object.getClass().getName()+"'");
	}
	return result;
}
 
Example #19
Source File: RDFEntity.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public Collection<String> getStrings(URI pred) {
	Collection<String> set = new ArrayList<String>();
	for (Value value : getValues(pred)) {
		if (value instanceof BNode) {
			for (Value v : new RDFList(model, (BNode) value).asList()) {
				if (v instanceof BNode)
					return Collections.EMPTY_SET;
				set.add(v.stringValue());
			}
		} else {
			set.add(value.stringValue());
		}
	}
	return set;
}
 
Example #20
Source File: IndividualImpl.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
IndividualImpl(Resource subject) {
	this.subject = subject;
	this.anonymous=subject instanceof BNode;
	if(anonymous && LOGGER.isTraceEnabled()) {
		LOGGER.trace(String.format("Individual '%s' is anonymous",subject));
	}
	this.predicates=new TreeSet<URI>(new PredicateComparator());
	this.protectedPredicates=Collections.unmodifiableSet(this.predicates);
	this.assertions=new HashMap<URI,AssertionsImpl>();
	this.referrers=new TreeSet<Resource>(new ResourceComparator());
	this.references=0;
}
 
Example #21
Source File: LexiconRelation.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles non-inline {@link IV}s by synthesizing a {@link BigdataBNode}
 * using {@link IV#bnodeId()} (iff told bnodes support is enabled and the
 * {@link IV} represents a blank node) and testing the {@link #termCache
 * term cache} otherwise.
 * 
 * @param iv
 *            A non-inline {@link IV}.
 * 
 * @return The corresponding {@link BigdataValue} if the {@link IV}
 *         represents a blank node or is found in the {@link #termCache},
 *         and <code>null</code> otherwise.
 * 
 * @throws IllegalArgumentException
 *             if <i>iv</i> is <code>null</code>
 * @throws IllegalArgumentException
 *             if {@link IV#isNullIV()}
 * @throws IllegalArgumentException
 *             if the {@link IV} is {@link IV#isInline()}.
 */
private BigdataValue _getTermId(final IV<?,?> iv) {

    if (iv == null)
        throw new IllegalArgumentException();

    if (iv.isNullIV())
        throw new IllegalArgumentException();

    if (iv.isInline()) // only for non-inline IVs.
        throw new IllegalArgumentException();
    
    if (!storeBlankNodes && iv.isBNode()) {

        /*
         * Except when the "told bnodes" mode is enabled, blank nodes are
         * not stored in the reverse lexicon (or the cache).
         * 
         * Note: In a told bnodes mode, we need to store the blank nodes in
         * the lexicon and enter them into the term cache since their
         * lexical form will include the specified ID, not the term
         * identifier.
         */

        final String id = 't' + ((BNode) iv).getID();

        final BigdataBNode bnode = valueFactory.createBNode(id);

        // set the term identifier on the object.
        bnode.setIV(iv);

        return bnode;

    }

    // Test the term cache.
    return termCache.get(iv);

}
 
Example #22
Source File: ResourceComparator.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
private int compareOther(Resource o1, Resource o2) {
	if(o2 instanceof BNode) {
		return o1.toString().compareTo(o2.toString());
	} else {
		return 1;
	}
}
 
Example #23
Source File: TransientValueDictionaryTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the value retrieval.
 * 
 * @throws Exception never otherwise the test fails.
 */
@Test
public void getValue() throws Exception {
	byte[] firstMemberId = _cut.getID(_firstMember, false);
	assertEquals(_firstMember, _cut.getValue(firstMemberId, false));

	byte[] fourthMemberId = _cut.getID(_fourthMember, false);
	assertEquals(_fourthMember, _cut.getValue(fourthMemberId, false));

	byte[] fifthMemberId = _cut.getID(_fifthMember, false);
	assertTrue(_cut.getValue(fifthMemberId, false) instanceof BNode);
}
 
Example #24
Source File: SPARQLJSONWriterBase.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected void writeValue(Value value)
	throws IOException, QueryResultHandlerException
{
	jg.writeStartObject();

	if (value instanceof URI) {
		jg.writeStringField("type", "uri");
		jg.writeStringField("value", ((URI)value).toString());
	}
	else if (value instanceof BNode) {
		jg.writeStringField("type", "bnode");
		jg.writeStringField("value", ((BNode)value).getID());
	}
	else if (value instanceof Literal) {
		Literal lit = (Literal)value;

		// TODO: Implement support for
		// BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL here
		if (lit.getLanguage() != null) {
			jg.writeObjectField("xml:lang", lit.getLanguage());
		}
		// TODO: Implement support for
		// BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL here
		if (lit.getDatatype() != null) {
			jg.writeObjectField("datatype", lit.getDatatype().stringValue());
		}

		jg.writeObjectField("type", "literal");

		jg.writeObjectField("value", lit.getLabel());
	}
	else {
		throw new TupleQueryResultHandlerException("Unknown Value object type: " + value.getClass());
	}
	jg.writeEndObject();
}
 
Example #25
Source File: CustomSesameDataset.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
/**
 * BNode factory
 * 
 * @return
 */
public BNode bnode() {
	try {
		RepositoryConnection con = currentRepository.getConnection();
		try {
			ValueFactory vf = con.getValueFactory();
			return vf.createBNode();
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
Example #26
Source File: CustomSesameDataset.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public boolean isBNode(Value value) {
	try {
		@SuppressWarnings("unused")
		BNode test = (BNode) value;
		return true;
	} catch (ClassCastException e) {
		return false;
	}
}
 
Example #27
Source File: IntegrationTestSupertypeLayer.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an in-memory clone of the incoming collection of statements. 
 * This is needed in order to execute comparisons between statements belonging to different value factories (e.g. InMemory and CumulusRDF).
 * 
 * @param model the set of statements to be cloned.
 * @return an in-memory clone of the incoming collection of statements.
 */
protected Set<Statement> statements(final Collection<? extends Statement> model) {
	final ValueFactory factory = inMemoryRepository.getValueFactory();
	return model
			.stream()
			.map(statement -> {
					Value object = null;
					if (statement.getObject() instanceof Literal) {
						Literal l = (Literal) statement.getObject();
						if (l.getLanguage() != null) {
							object = factory.createLiteral(l.getLabel(), l.getLanguage());								
						} else {
							object = factory.createLiteral(l.getLabel(), l.getDatatype());																
						}
					} else if (statement.getObject() instanceof BNode) {
						object = factory.createBNode(((BNode)statement.getObject()).getID()); 
					} else if (statement.getObject() instanceof URI) {
						object = factory.createURI(((URI)statement.getSubject()).stringValue());
					}
					
					return factory.createStatement(
						statement.getSubject() instanceof BNode 
							? factory.createBNode(((BNode)statement.getSubject()).getID()) 
							: factory.createURI(((URI)statement.getSubject()).stringValue()), 
						factory.createURI(((URI)statement.getPredicate()).stringValue()), 
						object);
			})
			.collect(toSet());
}
 
Example #28
Source File: TransientValueDictionary.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
protected byte[] getIdInternal(final Value value, final boolean p) throws DataAccessLayerException {		
	if (value instanceof Literal) {
		final Literal literal = (Literal) value;
		if (literal.getLabel().length() > _threshold) {
			final byte[] idFromEmbeddedDictionary = _longLiteralsDictionary.getID(value, p);
			final byte [] result = new byte[idFromEmbeddedDictionary.length + 1];
			result[0] = THRESHOLD_EXCEEDED;
			fillIn(result, 1, idFromEmbeddedDictionary);
			RUNTIME_CONTEXTS.get().isFirstLevelResult = false;
			return result;
		}
	} 
	 
	final String n3 = NTriplesUtil.toNTriplesString(value);

	final byte[] n3b = n3.getBytes(CHARSET_UTF8);
	final byte[] id = new byte[n3b.length + 2];
	
	if (value instanceof Literal) {
		id[0] = THRESHOLD_NOT_EXCEEDED;
		id[1] = LITERAL_BYTE_FLAG;
	} else if (value instanceof BNode) {
		id[0] = THRESHOLD_NOT_EXCEEDED;
		id[1] = BNODE_BYTE_FLAG;
	} else {
		id[0] = THRESHOLD_NOT_EXCEEDED;
		id[1] = RESOURCE_BYTE_FLAG;
	}		
	
	fillIn(id, 2, n3b);
	RUNTIME_CONTEXTS.get().isFirstLevelResult = true;
	return id;			
}
 
Example #29
Source File: NativeCumulusBNode.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(final Object object) {

	if (this == object) {
		return true;
	}

	if (!(object instanceof BNode)) {
		return false;
	}

	if (object instanceof NativeCumulusBNode && !Arrays.equals(_internalID, INativeCumulusValue.UNKNOWN_ID)) {

		NativeCumulusBNode other = (NativeCumulusBNode) object;

		if (!Arrays.equals(other._internalID, INativeCumulusValue.UNKNOWN_ID)) {
			return Arrays.equals(_internalID, other._internalID);
		}
	}

	// this should not happen -> _internalID should be used only!
	if (!_has_data) {
		load();
	}

	return super.equals(object);
}
 
Example #30
Source File: CumulusRDFValueFactory.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a CumulusRDF native value from a given {@link Value}.
 * 
 * @param value the incoming {@link Value}.
 * @return a CumulusRDF native value.
 */
public static Value makeNativeValue(final Value value) {
	if (value == null || value instanceof INativeCumulusValue) {
		return value;
	}

	if (value instanceof URI) {
		return new NativeCumulusURI(value.stringValue());
	} else if (value instanceof Literal) {
		
		final Literal lit = (Literal) value;
		final String label = lit.getLabel(), language = lit.getLanguage();
		final URI datatype = lit.getDatatype();

		if (language != null) {
			return new NativeCumulusLiteral(label, language);
		} else if (datatype != null) {
			return new NativeCumulusLiteral(label, datatype);
		} else {
			return new NativeCumulusLiteral(label);
		}
		
	} else if (value instanceof BNode) {
		return new NativeCumulusBNode(value.stringValue());
	}

	return value;
}