Java Code Examples for org.eclipse.rdf4j.model.Value#equals()

The following examples show how to use org.eclipse.rdf4j.model.Value#equals() . 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: ConformanceTest.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Determine that a statement is trivially true for purposes of entailment
 * tests, such as an implicit "[bnode] type Ontology" triple or a
 * "[class] type Class" triple as long as the class exists.
 */
boolean triviallyTrue(final Statement triple, final Schema schema) {
    final Resource s = triple.getSubject();
    final IRI p = triple.getPredicate();
    final Value o = triple.getObject();
    if (p.equals(RDF.TYPE)) {
        if (o.equals(OWL.ONTOLOGY)) {
            return true;
        }
        else if (o.equals(OWL.CLASS)) {
            return schema.hasClass(s);
        }
        else if ((o.equals(OWL.OBJECTPROPERTY)
            || o.equals(OWL.DATATYPEPROPERTY))
            && s instanceof IRI) {
            // Distinction not maintained, irrelevant to RL rules
            return schema.hasProperty((IRI) s);
        }
    }
    return false;
}
 
Example 2
Source File: HalyardValueExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate an {@link In} node
 * @param node the node to evaluate
 * @param bindings the set of named value bindings
 * @return
 * @throws ValueExprEvaluationException
 * @throws QueryEvaluationException
 */
private Value evaluate(In node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException {
    Value leftValue = evaluate(node.getArg(), bindings);
    // Result is false until a match has been found
    boolean result = false;
    // Use first binding name from tuple expr to compare values
    String bindingName = node.getSubQuery().getBindingNames().iterator().next();
    try (CloseableIteration<BindingSet, QueryEvaluationException> iter = parentStrategy.evaluate(node.getSubQuery(), bindings)) {
        while (result == false && iter.hasNext()) {
            BindingSet bindingSet = iter.next();
            Value rightValue = bindingSet.getValue(bindingName);
            result = leftValue == null && rightValue == null || leftValue != null
                    && leftValue.equals(rightValue);
        }
    }
    return BooleanLiteral.valueOf(result);
}
 
Example 3
Source File: HalyardTupleExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate {@link ZeroLengthPath} query model nodes
 * @param parent
 * @param zlp
 * @param bindings
 */
private void evaluateZeroLengthPath(BindingSetPipe parent, ZeroLengthPath zlp, BindingSet bindings) {
    final Var subjectVar = zlp.getSubjectVar();
    final Var objVar = zlp.getObjectVar();
    final Var contextVar = zlp.getContextVar();
    Value subj = subjectVar.getValue() == null ? bindings.getValue(subjectVar.getName()) : subjectVar.getValue();
    Value obj = objVar.getValue() == null ? bindings.getValue(objVar.getName()) : objVar.getValue();
    if (subj != null && obj != null) {
        if (!subj.equals(obj)) {
            try {
                parent.push(null);
            } catch (InterruptedException e) {
                parent.handleException(e);
            }
            return;
        }
    }
    //temporary solution using copy of the original iterator
    //re-writing this to push model is a bit more complex task
    HalyardStatementPatternEvaluation.enqueue(parent, new ZeroLengthPathIteration(parentStrategy, subjectVar, objVar, subj, obj, contextVar, bindings), zlp);
}
 
Example 4
Source File: Models.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static boolean bnodeValueMatching(Map<Resource, Resource> bNodeMapping, Value obj1, Value obj2) {
	if (isBlank(obj1) && isBlank(obj2)) {
		Resource mappedBNode = bNodeMapping.get(obj1);

		if (mappedBNode != null) {
			// bNode 'obj1' was already mapped to some other bNode
			// 'obj1' and 'obj2' do not match
			return !obj2.equals(mappedBNode);
		} else {
			// 'obj1' was not yet mapped. we need to check if 'obj2' is a
			// possible mapping candidate
			// 'obj2' is already mapped to some other value.
			return bNodeMapping.containsValue(obj2);
		}
	} else {
		// objects are not (both) bNodes
		return !obj1.equals(obj2);
	}
}
 
Example 5
Source File: QueryResults.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check whether two {@link BindingSet}s are compatible.Two binding sets are compatible if they have equal values
 * for each binding name that occurs in both binding sets.
 *
 * @param bs1
 * @param bs2
 * @return true if compatible
 */
public static boolean bindingSetsCompatible(BindingSet bs1, BindingSet bs2) {
	Set<String> sharedBindings = new HashSet<>(bs1.getBindingNames());
	sharedBindings.retainAll(bs2.getBindingNames());

	for (String bindingName : sharedBindings) {
		Value value1 = bs1.getValue(bindingName);
		Value value2 = bs2.getValue(bindingName);

		if (!value1.equals(value2)) {
			return false;
		}
	}

	return true;
}
 
Example 6
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Value evaluate(In node, BindingSet bindings) throws QueryEvaluationException {
	Value leftValue = evaluate(node.getArg(), bindings);

	// Result is false until a match has been found
	boolean result = false;

	// Use first binding name from tuple expr to compare values
	String bindingName = node.getSubQuery().getBindingNames().iterator().next();

	try (CloseableIteration<BindingSet, QueryEvaluationException> iter = evaluate(node.getSubQuery(), bindings)) {
		while (!result && iter.hasNext()) {
			BindingSet bindingSet = iter.next();

			Value rightValue = bindingSet.getValue(bindingName);

			result = leftValue == null && rightValue == null || leftValue != null && leftValue.equals(rightValue);
		}
	}

	return BooleanLiteral.valueOf(result);
}
 
Example 7
Source File: BindingSetHashKey.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean equals(Object o) {
	if (o == this) {
		return true;
	}
	if (!(o instanceof BindingSetHashKey)) {
		return false;
	}

	BindingSetHashKey jk = (BindingSetHashKey) o;
	if (this.values.length != jk.values.length) {
		return false;
	}

	for (int i = values.length - 1; i >= 0; i--) {
		final Value v1 = this.values[i];
		final Value v2 = jk.values[i];

		if (v1 == null) {
			if (v2 != null) {
				return false;
			}
		} else {
			if (!v1.equals(v2)) {
				return false;
			}
		}
	}
	return true;
}
 
Example 8
Source File: VOIDStatistics.java    From semagrow with Apache License 2.0 5 votes vote down vote up
private boolean isTypeClass(StatementPattern pattern) {
    Value predVal = pattern.getPredicateVar().getValue();
    Value objVal = pattern.getObjectVar().getValue();

    if (predVal != null && objVal != null && predVal.equals(RDF.TYPE))
        return true;
    else
        return false;
}
 
Example 9
Source File: PatternIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Tests whether or not the specified statement should be returned by this iterator. All objects from the wrapped
 * iterator pass through this method in the same order as they are coming from the wrapped iterator.
 *
 * @param st The statement to be tested.
 * @return <tt>true</tt> if the object should be returned, <tt>false</tt> otherwise.
 */
protected boolean accept(S st) {
	if (subj != null && !subj.equals(st.getSubject())) {
		return false;
	}
	if (pred != null && !pred.equals(st.getPredicate())) {
		return false;
	}
	if (obj != null && !obj.equals(st.getObject())) {
		return false;
	}
	Resource stContext = st.getContext();
	if (contexts != null && contexts.length == 0) {
		// Any context matches
		return true;
	} else {
		// Accept if one of the contexts from the pattern matches
		for (Value context : notNull(contexts)) {
			if (context == null && stContext == null) {
				return true;
			}
			if (context != null && context.equals(stContext)) {
				return true;
			}
		}

		return false;
	}
}
 
Example 10
Source File: LocalRepositoryManager.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void remove(RepositoryConnection conn, Resource subject, IRI predicate, Value object,
		Resource... contexts) {
	if (object != null && object.equals(RepositoryConfigSchema.REPOSITORY_CONTEXT)) {
		if (subject == null) {
			modifiedAllContextsByConnection.put(conn, true);
		} else {
			Set<Resource> removedContexts = getRemovedContexts(conn);
			removedContexts.add(subject);
		}
	}
	registerModifiedContexts(conn, contexts);
}
 
Example 11
Source File: EndpointFactory.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Endpoint loadEndpoint(Config config, HttpClient httpClient, Model graph, Resource repNode, Value repType) throws FedXException {
	
	EndpointProvider repProvider;
	
	// NativeStore => Sesame native store implementation
	if (repType.equals(SimpleValueFactory.getInstance().createLiteral("NativeStore"))){
		repProvider = new NativeStoreProvider(config);
		return repProvider.loadEndpoint(new NativeGraphRepositoryInformation(graph, repNode) );
	} 
	
	// SPARQL Repository => SPARQLRepository 
	else if (repType.equals(SimpleValueFactory.getInstance().createLiteral("SPARQLEndpoint"))){
		repProvider = new SPARQLProvider(config, httpClient);	 
		return repProvider.loadEndpoint(new SPARQLGraphRepositoryInformation(graph, repNode) );
	} 
	
	// Remote Repository
	else if (repType.equals(SimpleValueFactory.getInstance().createLiteral("RemoteRepository"))){
		repProvider =  new RemoteRepositoryProvider(config);	 
		return repProvider.loadEndpoint(new RemoteRepositoryGraphRepositoryInformation(graph, repNode) );
	} 
	
	// other generic type
	else if (repType.equals(SimpleValueFactory.getInstance().createLiteral("Other"))) {
		
		// TODO add reflection techniques to allow for flexibility
		throw new UnsupportedOperationException("Operation not yet supported for generic type.");
		
	}
	
	else {
		throw new FedXRuntimeException("Repository type not supported: " + repType.stringValue());
	}
	
	
}
 
Example 12
Source File: BinaryQueryResultWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void handleSolutionImpl(BindingSet bindingSet) throws TupleQueryResultHandlerException {
	if (!tupleVariablesFound) {
		throw new IllegalStateException("Must call startQueryResult before handleSolution");
	}

	try {
		if (bindingSet.size() == 0) {
			writeEmptyRow();
		} else {
			for (String bindingName : bindingNames) {
				Value value = bindingSet.getValue(bindingName);

				if (value == null) {
					writeNull();
				} else if (value.equals(previousBindings.getValue(bindingName))) {
					writeRepeat();
				} else {
					writeValue(value);
				}
			}

			previousBindings = bindingSet;
		}
	} catch (IOException e) {
		throw new TupleQueryResultHandlerException(e);
	}
}
 
Example 13
Source File: BindingSetUtil.java    From semagrow with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the value of every binding name on first agrees with
 * the value of the binding name (if exists) on the second bindingset
 * @param first
 * @param second
 * @return true or false
 */
public static boolean agreesOn(BindingSet first, BindingSet second) {

    for (Binding b : first) {
        Value v = second.getValue(b.getName());
        if (v != null && !v.equals(b.getValue()))
            return false;
    }
    return true;
}
 
Example 14
Source File: QueryEvaluationUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean valuesEqual(Value leftVal, Value rightVal) {
	return leftVal != null && rightVal != null && leftVal.equals(rightVal);
}
 
Example 15
Source File: QueryResults.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean bindingSetsMatch(BindingSet bs1, BindingSet bs2, Map<BNode, BNode> bNodeMapping) {

		if (bs1.size() != bs2.size()) {
			return false;
		}

		for (Binding binding1 : bs1) {
			Value value1 = binding1.getValue();
			Value value2 = bs2.getValue(binding1.getName());

			if (value1 instanceof BNode && value2 instanceof BNode) {
				BNode mappedBNode = bNodeMapping.get(value1);

				if (mappedBNode != null) {
					// bNode 'value1' was already mapped to some other bNode
					if (!value2.equals(mappedBNode)) {
						// 'value1' and 'value2' do not match
						return false;
					}
				} else {
					// 'value1' was not yet mapped, we need to check if 'value2' is a
					// possible mapping candidate
					if (bNodeMapping.containsValue(value2)) {
						// 'value2' is already mapped to some other value.
						return false;
					}
				}
			} else {
				// values are not (both) bNodes
				if (value1 instanceof Literal && value2 instanceof Literal) {
					// do literal value-based comparison for supported datatypes
					Literal leftLit = (Literal) value1;
					Literal rightLit = (Literal) value2;

					IRI dt1 = leftLit.getDatatype();
					IRI dt2 = rightLit.getDatatype();

					if (dt1 != null && dt2 != null && dt1.equals(dt2)
							&& XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
							&& XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
						Integer compareResult = null;
						if (dt1.equals(XMLSchema.DOUBLE)) {
							compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
						} else if (dt1.equals(XMLSchema.FLOAT)) {
							compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
						} else if (dt1.equals(XMLSchema.DECIMAL)) {
							compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
						} else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
							compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
						} else if (dt1.equals(XMLSchema.BOOLEAN)) {
							Boolean leftBool = leftLit.booleanValue();
							Boolean rightBool = rightLit.booleanValue();
							compareResult = leftBool.compareTo(rightBool);
						} else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
							XMLGregorianCalendar left = leftLit.calendarValue();
							XMLGregorianCalendar right = rightLit.calendarValue();

							compareResult = left.compare(right);
						}

						if (compareResult != null) {
							if (compareResult.intValue() != 0) {
								return false;
							}
						} else if (!value1.equals(value2)) {
							return false;
						}
					} else if (!value1.equals(value2)) {
						return false;
					}
				} else if (!value1.equals(value2)) {
					return false;
				}
			}
		}

		return true;
	}
 
Example 16
Source File: CSVQueryResultsComparisons.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean valuesEqual(Value leftVal, Value rightVal) {
	return leftVal != null && rightVal != null && leftVal.equals(rightVal);
}
 
Example 17
Source File: Schema.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * Determine whether a fact is contained in the Schema object
 * relationships or implied by schema rules.
 * @return  True if this schema contains the semantics of the triple
 */
public boolean containsTriple(Statement triple) {
    // The schema certainly doesn't contain it if it's not a
    // schema-relevant triple at all.
    if (isSchemaTriple(triple)) {
        Resource s = triple.getSubject();
        IRI p = triple.getPredicate();
        Value o = triple.getObject();
        // If this is telling us something about a property:
        if (properties.containsKey(s)) {
            OwlProperty prop = properties.get(s);
            // Property types:
            if (p.equals(RDF.TYPE)) {
                if ((o.equals(OWL.TRANSITIVEPROPERTY)
                        && prop.isTransitive())
                    || (o.equals(OWL2.IRREFLEXIVEPROPERTY)
                        && prop.isIrreflexive())
                    || (o.equals(OWL.SYMMETRICPROPERTY)
                        && prop.isSymmetric())
                    || (o.equals(OWL2.ASYMMETRICPROPERTY)
                        && prop.isAsymmetric())
                    || (o.equals(OWL.FUNCTIONALPROPERTY)
                        && prop.isFunctional())
                    || (o.equals(OWL.INVERSEFUNCTIONALPROPERTY)
                        && prop.isInverseFunctional())) {
                    return true;
                }
            }
            // Relationships with other properties:
            if ((p.equals(RDFS.SUBPROPERTYOF)
                    && prop.getSuperProperties().contains(o))
                || (p.equals(OWL2.PROPERTYDISJOINTWITH)
                    && prop.getDisjointProperties().contains(o))
                || (p.equals(OWL.EQUIVALENTPROPERTY)
                    && prop.getEquivalentProperties().contains(o))
                || (p.equals(OWL.INVERSEOF)
                    && prop.getInverseProperties().contains(o))) {
                return true;
            }
            // Relationships with classes:
            if ((p.equals(RDFS.DOMAIN)
                    && prop.getDomain().contains(o))
                || (p.equals(RDFS.RANGE)
                    && prop.getRange().contains(o))) {
                return true;
            }
        }
        // If this is about a class relationship:
        if (classes.containsKey(s)) {
            OwlClass subject = classes.get(s);
            if ((p.equals(OWL.EQUIVALENTCLASS)
                    && (subject.getEquivalentClasses().contains(o)))
                || (p.equals(OWL.DISJOINTWITH)
                    && (subject.getDisjointClasses().contains(o)))
                || (p.equals(OWL.COMPLEMENTOF)
                    && (subject.getComplementaryClasses().contains(o)))
                || (p.equals(RDFS.SUBCLASSOF)
                    && (subject.getSuperClasses().contains(o)))) {
                return true;
            }
        }
    }
    return false;
}
 
Example 18
Source File: SchemaCachingRDFSInferencerConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void processForSchemaCache(Statement statement) {
	sail.acquireExclusiveWriteLock();

	final IRI predicate = statement.getPredicate();
	final Value object = statement.getObject();
	final Resource subject = statement.getSubject();

	if (predicate.equals(RDFS.SUBCLASSOF)) {
		sail.addSubClassOfStatement(statement);
		schemaChange = true;
	} else if (predicate.equals(RDF.TYPE) && object.equals(RDF.PROPERTY)) {
		sail.addProperty(subject);
		schemaChange = true;
	} else if (predicate.equals(RDFS.SUBPROPERTYOF)) {
		sail.addSubPropertyOfStatement(statement);
		schemaChange = true;
	} else if (predicate.equals(RDFS.RANGE)) {
		sail.addRangeStatement(statement);
		schemaChange = true;
	} else if (predicate.equals(RDFS.DOMAIN)) {
		sail.addDomainStatement(statement);
		schemaChange = true;
	} else if (predicate.equals(RDF.TYPE) && object.equals(RDFS.CLASS)) {
		sail.addSubClassOfStatement(
				sail.getValueFactory().createStatement(subject, RDFS.SUBCLASSOF, RDFS.RESOURCE));
		schemaChange = true;
	} else if (predicate.equals(RDF.TYPE) && object.equals(RDFS.DATATYPE)) {
		sail.addSubClassOfStatement(
				sail.getValueFactory().createStatement(subject, RDFS.SUBCLASSOF, RDFS.LITERAL));
		schemaChange = true;
	} else if (predicate.equals(RDF.TYPE) && object.equals(RDFS.CONTAINERMEMBERSHIPPROPERTY)) {
		sail.addSubPropertyOfStatement(
				sail.getValueFactory().createStatement(subject, RDFS.SUBPROPERTYOF, RDFS.MEMBER));
		schemaChange = true;
	} else if (predicate.equals(RDF.TYPE)) {
		if (!sail.hasType(((Resource) object))) {
			sail.addType((Resource) object);
			schemaChange = true;
		}
	}

	if (!sail.hasProperty(predicate)) {
		sail.addProperty(predicate);
		schemaChange = true;
	}

}
 
Example 19
Source File: Schema.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * Incorporate a new triple into the schema.
 */
public void processTriple(Statement triple) {
    Resource s = triple.getSubject();
    IRI p = triple.getPredicate();
    Value o = triple.getObject();
    if (isSchemaTriple(triple)) {
        // For a type statement to be schema information, it must yield
        // some boolean information about a property.
        if (p.equals(RDF.TYPE)) {
            if (schemaTypes.contains(o)) {
                addPropertyType((IRI) s, (Resource) o);
            }
        }

        // Domain/range
        else if (p.equals(RDFS.DOMAIN)) {
            // Don't add trivial domain owl:Thing
            if (!o.equals(OWL.THING)) {
                getProperty(s).addDomain(getClass(o));
            }
        }
        else if (p.equals(RDFS.RANGE)) {
            // Don't add trivial range owl:Thing
            if (!o.equals(OWL.THING)) {
                getProperty(s).addRange(getClass(o));
            }
        }

        // Sub/super relations
        else if (p.equals(RDFS.SUBCLASSOF)) {
            // Everything is a subclass of owl#Thing, we don't need to
            // store that information
            if (!o.equals(OWL.THING)) {
                getClass(s).addSuperClass(getClass(o));
            }
        }
        else if (p.equals(RDFS.SUBPROPERTYOF)) {
            getProperty(s).addSuperProperty(getProperty(o));
        }

        // Equivalence relations
        else if (p.equals(OWL.EQUIVALENTCLASS)) {
            getClass(s).addEquivalentClass(getClass(o));
        }
        else if (p.equals(OWL.EQUIVALENTPROPERTY)) {
            getProperty(s).addEquivalentProperty(getProperty(o));
        }

        // Inverse properties
        else if (p.equals(OWL.INVERSEOF)) {
            getProperty(s).addInverse(getProperty(o));
            getProperty(o).addInverse(getProperty(s));
        }

        // Complementary classes
        else if (p.equals(OWL.COMPLEMENTOF)) {
            getClass(s).addComplement(getClass(o));
            getClass(o).addComplement(getClass(s));
        }

        // Disjoint classes and properties
        else if (p.equals(OWL.DISJOINTWITH)) {
            getClass(s).addDisjoint(getClass(o));
            getClass(o).addDisjoint(getClass(s));
        }
        else if (p.equals(OWL2.PROPERTYDISJOINTWITH)) {
            getProperty(s).addDisjoint(getProperty(o));
            getProperty(o).addDisjoint(getProperty(s));
        }

        // Property restriction info
        else if (p.equals(OWL.ONPROPERTY)) {
            getClass(s).addProperty(getProperty(o));
        }
        else if (p.equals(OWL.SOMEVALUESFROM)) {
            getClass(s).addSvf(getClass(o));
        }
        else if (p.equals(OWL.ALLVALUESFROM)) {
            getClass(s).addAvf(getClass(o));
        }
        else if (p.equals(OWL2.ONCLASS)) {
            getClass(s).addClass(getClass(o));
        }
        else if (p.equals(OWL.HASVALUE)) {
            getClass(s).addValue(o);
        }
        else if (p.equals(OWL.MAXCARDINALITY)) {
            getClass(s).setMaxCardinality(o);
        }
        else if (p.equals(OWL2.MAXQUALIFIEDCARDINALITY)) {
            getClass(s).setMaxQualifiedCardinality(o);
        }
    }
}
 
Example 20
Source File: TurtleWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Writes a value, optionally shortening it if it is an {@link IRI} and has a namespace definition that is suitable
 * for use in this context for shortening or a {@link BNode} that has been confirmed to be able to be shortened in
 * this context.
 *
 * @param val        The {@link Value} to write.
 * @param canShorten True if, in the current context, we can shorten this value if it is an instance of
 *                   {@link BNode} .
 * @throws IOException
 */
protected void writeValue(Value val, boolean canShorten) throws IOException {
	if (val instanceof BNode && canShorten && !val.equals(stack.peekLast()) && !val.equals(lastWrittenSubject)) {
		stack.addLast((BNode) val);
	} else if (val instanceof Resource) {
		writeResource((Resource) val, canShorten);
	} else {
		writeLiteral((Literal) val);
	}
}