Java Code Examples for org.openrdf.model.URI#equals()
The following examples show how to use
org.openrdf.model.URI#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: XMLGregorianCalendarMarshall.java From anno4j with Apache License 2.0 | 6 votes |
public void setDatatype(URI datatype) { if (datatype.equals(XMLSchema.DATETIME)) return; if (datatype.equals(XMLSchema.DATE)) return; if (datatype.equals(XMLSchema.TIME)) return; if (datatype.equals(XMLSchema.GYEARMONTH)) return; if (datatype.equals(XMLSchema.GMONTHDAY)) return; if (datatype.equals(XMLSchema.GYEAR)) return; if (datatype.equals(XMLSchema.GMONTH)) return; if (datatype.equals(XMLSchema.GDAY)) return; throw new IllegalArgumentException(datatype.toString()); }
Example 2
Source File: MathUtility.java From database with GNU General Public License v2.0 | 5 votes |
/** * The XPath numeric functions: abs, ceiling, floor, and round. * * @param iv1 * The operand. * @param op * The operation. * @return The result. * * @see XPathMathFunctions */ public final static NumericIV numericalFunc(final Literal lit, final NumericOp op) { if (!checkNumericDatatype(lit)) throw new IllegalArgumentException("not numeric: " + lit); final URI dte1 = lit.getDatatype(); /* * FIXME These xpath functions have very custom semantics. They need to * be lifted out of this class and put into their own static methods * with their own test suites. */ // switch (op) { // case ABS: // return XPathMathFunctions.abs(iv1); // case CEIL: // return XPathMathFunctions.ceiling(iv1); // case FLOOR: // return XPathMathFunctions.floor(iv1); // case ROUND: // return XPathMathFunctions.round(iv1); // default: // throw new UnsupportedOperationException(op.toString()); // } if (dte1.equals(XMLSchema.DECIMAL)) { return numericalFunc(lit.decimalValue(), op); } else if (dte1.equals(XMLSchema.INTEGER)) { return numericalFunc(lit.integerValue(), op); } else if (dte1.equals(XMLSchema.FLOAT)) { return numericalFunc(lit.floatValue(), op); } else if (dte1.equals(XMLSchema.INT)) { return numericalFunc(lit.intValue(), op); } else if (dte1.equals(XMLSchema.DOUBLE)) { return numericalFunc(lit.doubleValue(), op); } else { return numericalFunc(lit.longValue(), op); } }
Example 3
Source File: FulltextSearchServiceFactory.java From database with GNU General Public License v2.0 | 5 votes |
@Override public Set<IVariable<?>> getRequiredBound(final ServiceNode serviceNode) { /** * This method extracts exactly those variables that are incoming, * i.e. must be bound before executing the execution of the service. */ final Set<IVariable<?>> requiredBound = new HashSet<IVariable<?>>(); for (StatementPatternNode sp : getStatementPatterns(serviceNode)) { final URI predicate = (URI) (sp.p()).getValue(); final IVariableOrConstant<?> object = sp.o().getValueExpression(); if (object instanceof IVariable<?>) { if (predicate.equals(FTS.SEARCH) || predicate.equals(FTS.ENDPOINT) || predicate.equals(FTS.ENDPOINT_TYPE) || predicate.equals(FTS.PARAMS) || predicate.equals(FTS.SEARCH_RESULT_TYPE) || predicate.equals(FTS.SEARCH_FIELD) || predicate.equals(FTS.SCORE_FIELD) || predicate.equals(FTS.SNIPPET_FIELD) || predicate.equals(FTS.TIMEOUT)) { requiredBound.add((IVariable<?>)object); // the subject var is what we return } } } return requiredBound; }
Example 4
Source File: BigDecimalMarshall.java From anno4j with Apache License 2.0 | 4 votes |
public void setDatatype(URI dt) { if (!dt.equals(datatype)) throw new IllegalArgumentException(dt.toString()); }
Example 5
Source File: TestFederatedQuery.java From database with GNU General Public License v2.0 | 4 votes |
public void testSimpleServiceQuery() throws Exception { // test setup final String EX_NS = "http://example.org/"; final ValueFactory f = new ValueFactoryImpl(); final URI bob = f.createURI(EX_NS, "bob"); final URI alice = f.createURI(EX_NS, "alice"); final URI william = f.createURI(EX_NS, "william"); // clears the repository and adds new data prepareTest("simple-default-graph.ttl", Arrays.asList("simple.ttl")); final StringBuilder qb = new StringBuilder(); qb.append(" SELECT * \n"); qb.append(" WHERE { \n"); qb.append(" SERVICE <" + getRepositoryUrl(1) + "> { \n"); qb.append(" ?X <" + FOAF.NAME + "> ?Y \n "); qb.append(" } \n "); qb.append(" ?X a <" + FOAF.PERSON + "> . \n"); qb.append(" } \n"); final BigdataSailRemoteRepositoryConnection conn = m_repo.getBigdataSailRemoteRepository().getConnection(); try { final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, qb.toString()); final TupleQueryResult tqr = tq.evaluate(); assertNotNull(tqr); assertTrue("No solutions.", tqr.hasNext()); int count = 0; while (tqr.hasNext()) { final BindingSet bs = tqr.next(); count++; final Value x = bs.getValue("X"); final Value y = bs.getValue("Y"); assertFalse(william.equals(x)); assertTrue(bob.equals(x) || alice.equals(x)); if (bob.equals(x)) { f.createLiteral("Bob").equals(y); } else if (alice.equals(x)) { f.createLiteral("Alice").equals(y); } } assertEquals(2, count); } finally { conn.close(); } }
Example 6
Source File: BigdataGraph.java From database with GNU General Public License v2.0 | 4 votes |
/** * Convert a unit of RDF data to an atomic unit of PG data. */ protected BigdataGraphAtom toGraphAtom(final URI s, final URI p, final Value o) { final String sid = factory.fromURI(s); final String pid = factory.fromURI(p); final BigdataGraphAtom atom; if (o instanceof URI) { /* * Either an edge or an element type statement. */ if (p.equals(factory.getTypeURI()) && (o.equals(factory.getVertexURI()) || o.equals(factory.getEdgeURI()))) { /* * Element type. */ if (o.equals(factory.getVertexURI())) { atom = new ExistenceAtom(sid, ElementType.VERTEX); } else { atom = new ExistenceAtom(sid, ElementType.EDGE); } } else { /* * Edge. */ final String oid = factory.fromURI((URI) o); atom = new EdgeAtom(pid, sid, oid); } } else { /* * A property or the edge label. */ if (p.equals(factory.getLabelURI())) { /* * Edge label. */ final String label = factory.fromLiteral((Literal) o).toString(); atom = new EdgeLabelAtom(sid, label); } else { /* * Property. */ final Object oval = factory.fromLiteral((Literal) o); atom = new PropertyAtom(sid, pid, oval); } } return atom; }
Example 7
Source File: ShortMarshall.java From anno4j with Apache License 2.0 | 4 votes |
public void setDatatype(URI datatype) { if (!datatype.equals(XMLSchema.SHORT)) throw new IllegalArgumentException(datatype.toString()); }
Example 8
Source File: GASService.java From database with GNU General Public License v2.0 | 4 votes |
/** * Return the variable associated with the first instandce of the * specified subject and predicate in the service's graph pattern. Only * the simple {@link StatementPatternNode}s are visited. * * @param s * The subject. * @param p * The predicate. * * @return The variable -or- <code>null</code> if the specified subject * and predicate do not appear. */ private IVariable<?> getVar(final URI s, final URI p) { if (s == null) throw new IllegalArgumentException(); if (p == null) throw new IllegalArgumentException(); List<Value> tmp = null; final Iterator<IGroupMemberNode> itr = graphPattern.getChildren() .iterator(); while (itr.hasNext()) { final IGroupMemberNode child = itr.next(); if (!(child instanceof StatementPatternNode)) continue; final StatementPatternNode sp = (StatementPatternNode) child; // s and p are constants. if (!sp.s().isConstant()) continue; if (!sp.p().isConstant()) continue; // constants match. if (!s.equals(sp.s().getValue())) continue; if (!p.equals(sp.p().getValue())) continue; if (tmp == null) tmp = new LinkedList<Value>(); // found an o. return ((VarNode)sp.o()).getValueExpression(); } return null; // not found. }
Example 9
Source File: LexiconKeyBuilder.java From database with GNU General Public License v2.0 | 4 votes |
/** * Formats a datatype literal sort key. The value is formated according to * the datatype URI. * * @param datatype * @param value * @return */ public byte[] datatypeLiteral2key(final URI datatype, final String value) { if (datatype == null) throw new IllegalArgumentException(); if (value == null) throw new IllegalArgumentException(); if (false && datatype.equals(XMLSchema.STRING)) { /* * @todo xsd:string is explicitly mapped by RDF Semantics onto plain * literals (they entail one another). However, it breaks the SPARQL * unit tests if you map them onto the same key. */ return plainLiteral2key(value); } /* * Note: The full lexical form of the data type URI is serialized into * the key as a Unicode sort key followed by a nul byte and then a * Unicode sort key formed from the lexical form of the data type value. */ // clear out any existing key and add prefix for the DTL space. keyBuilder.reset().append(TERM_CODE_DTL); // encode the datatype URI as Unicode sort key to make all data // types disjoint. keyBuilder.append(datatype.stringValue()); // encode the datatype value as Unicode sort key. keyBuilder.append(value); keyBuilder.appendNul(); return keyBuilder.getKey(); }
Example 10
Source File: BigIntegerMarshall.java From anno4j with Apache License 2.0 | 4 votes |
public void setDatatype(URI dt) { if (!dt.equals(datatype)) throw new IllegalArgumentException(dt.toString()); }
Example 11
Source File: ByteMarshall.java From anno4j with Apache License 2.0 | 4 votes |
public void setDatatype(URI datatype) { if (!datatype.equals(XMLSchema.BYTE)) throw new IllegalArgumentException(datatype.toString()); }
Example 12
Source File: StaticAnalysis.java From database with GNU General Public License v2.0 | 4 votes |
/** * Recursively pushes logical ORs below logical ANDs in the operator tree, * such that in the returned node all OR expressions are situated below * AND expressions. Expectes that all NOT expressions have been pushed * down to the bottom already (otherwise, the behavior is undertermined). * * The resulting {@link IValueExpressionNode} is logically equivalent. */ static public IValueExpressionNode pushDisjuncts( final IValueExpressionNode vexp) { if(!(vexp instanceof FunctionNode)) { return vexp; } final FunctionNode functionNode = (FunctionNode)vexp; final URI functionURI = functionNode.getFunctionURI(); if (functionURI.equals(FunctionRegistry.OR)) { // first, recurse, making sure that AND is propagated up in the subtrees final IValueExpressionNode left = pushNegations( pushDisjuncts((IValueExpressionNode) functionNode.get(0))); final IValueExpressionNode right = pushNegations( pushDisjuncts((IValueExpressionNode) functionNode.get(1))); /* * New conjuncts are basically the cross product disjuncts of the left * and right subtree. Note that the special case (where neither the * left nor the right subtree has an AND at the top nicely fits in: * in that case, leftConjuncts and rightConjuncts have one element, * say x and y, and we compute x OR y as the one and only conjunct * (thus not changing the tree). */ final List<IValueExpressionNode> leftConjuncts = extractToplevelConjuncts( left, new ArrayList<IValueExpressionNode>()); final List<IValueExpressionNode> rightConjuncts = extractToplevelConjuncts( right, new ArrayList<IValueExpressionNode>()); final List<IValueExpressionNode> newConjuncts = new ArrayList<IValueExpressionNode>(); for (IValueExpressionNode leftConjunct : leftConjuncts) { for (IValueExpressionNode rightConjunct : rightConjuncts) { final IValueExpressionNode newConjunct = FunctionNode.OR( (ValueExpressionNode)leftConjunct, (ValueExpressionNode)rightConjunct); newConjuncts.add(newConjunct); } } return toConjunctiveValueExpression(newConjuncts); } else if (functionURI.equals(FunctionRegistry.AND)) { // just recurse return FunctionNode.AND( (ValueExpressionNode)pushDisjuncts( (IValueExpressionNode) functionNode.get(0)), (ValueExpressionNode)pushDisjuncts( (IValueExpressionNode) functionNode.get(1))); } // we're done recursing, no disjuncts will be found below this point return vexp; // return the (possibly modified) vexp }
Example 13
Source File: IntegerMarshall.java From anno4j with Apache License 2.0 | 4 votes |
public void setDatatype(URI datatype) { if (!datatype.equals(XMLSchema.INT)) throw new IllegalArgumentException(datatype.toString()); }
Example 14
Source File: NumericBOp.java From database with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("rawtypes") public IV get(final IBindingSet bs) { final Literal lit = super.getAndCheckLiteralValue(0, bs); final URI dt = lit.getDatatype(); final NumericOp op = op(); if ((dt.equals(XMLSchema.INT) || dt.equals(XMLSchema.INTEGER)) && (op == NumericOp.CEIL || op == NumericOp.FLOOR || op == NumericOp.ROUND)) { return get(0).get(bs); } if (log.isDebugEnabled()) log.debug(lit); return MathUtility.numericalFunc(lit, op()); }
Example 15
Source File: WebTestUtils.java From cumulusrdf with Apache License 2.0 | 4 votes |
/** * Copied from org.openrdf.query.QueryResultUtil */ private static boolean bindingSetsMatch(final BindingSet bs1, final BindingSet bs2) { 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; // } // } return value1.equals(value2); } 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; URI dt1 = leftLit.getDatatype(); URI 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 = Boolean.valueOf(leftLit.booleanValue()); Boolean rightBool = Boolean.valueOf(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: ConcatBOp.java From database with GNU General Public License v2.0 | 4 votes |
@Override public IV get(final IBindingSet bs) { URI datatype = null; String lang = null; boolean allSame = true; final StringBuilder sb = new StringBuilder(); for (int i = 0; i < arity(); i++) { @SuppressWarnings("rawtypes") final IV v = getAndCheckLiteral(i, bs); if (v.isNumeric()) { throw new SparqlTypeErrorException(); } String label = null; if (allSame) { final Literal lit = asLiteral(v); label = lit.getLabel(); if (lit.getDatatype() != null) { if (lang != null) { allSame = false; } else if (datatype == null) { if (i == 0) { datatype = lit.getDatatype(); } else { allSame = false; } } else if (!datatype.equals(lit.getDatatype())) { allSame = false; } } else if (lit.getLanguage() != null) { if (datatype != null) { allSame = false; } else if (lang == null) { if (i == 0) { lang = lit.getLanguage(); } else { allSame = false; } } else if (!lang.equals(lit.getLanguage())) { allSame = false; } } else { allSame = false; } } else { label = literalLabel(v); } sb.append(label); } if (allSame) { if (datatype != null) { return super.asIV(getValueFactory().createLiteral(sb.toString(),datatype), bs); } else if (lang != null) { return super.asIV(getValueFactory().createLiteral(sb.toString(),lang), bs); } } return super.asIV(getValueFactory().createLiteral(sb.toString()), bs); }
Example 17
Source File: ValueExprBuilder.java From database with GNU General Public License v2.0 | 3 votes |
/** * Handle a simple nary function (all children of the node are arguments to * the function). */ protected FunctionNode nary(final SimpleNode node, final URI functionURI) throws VisitorException { final int nargs = node.jjtGetNumChildren(); final ValueExpressionNode[] args = new ValueExpressionNode[nargs]; for (int i = 0; i < nargs; i++) { final Node argNode = node.jjtGetChild(i); args[i] = (ValueExpressionNode) argNode.jjtAccept(this, null); } if (functionURI.equals(FunctionRegistry.COALESCE)) { return new FunctionNode(FunctionRegistry.COALESCE, null/* scalarValues */, args); } else if (functionURI.equals(FN.SUBSTRING)) { return new FunctionNode(FunctionRegistry.SUBSTR, null/* scalarValues */, args); } else if (functionURI.equals(FN.CONCAT)) { return new FunctionNode(FunctionRegistry.CONCAT, null/* scalarValues */, args); } else { throw new IllegalArgumentException(); } }
Example 18
Source File: ASTFilterNormalizationOptimizer.java From database with GNU General Public License v2.0 | 3 votes |
/** * Checks if there might be potential for decomposing the filter * (overestimation). * * @param filterNode * @return */ public boolean isDecomposable(final IValueExpressionNode vexpr) { if(!(vexpr instanceof FunctionNode)) { return false; } final FunctionNode functionNode = (FunctionNode)vexpr; final URI functionURI = functionNode.getFunctionURI(); if (functionURI.equals(FunctionRegistry.AND) || functionURI.equals(FunctionRegistry.OR)) { return true; } else if (functionURI.equals(FunctionRegistry.NOT)) { final BOp bop = functionNode.get(0); if (bop instanceof FunctionNode) { return isDecomposable((FunctionNode)bop); } } // fallback: no decomposition opportunities identified return false; }
Example 19
Source File: SearchServiceFactory.java From database with GNU General Public License v2.0 | 2 votes |
/** * Validate the search. There must be exactly one {@link BD#SEARCH} * predicate. There should not be duplicates of any of the search predicates * for a given searchVar. */ private void validateSearch(final IVariable<?> searchVar, final Map<URI, StatementPatternNode> statementPatterns) { final Set<URI> uris = new LinkedHashSet<URI>(); for(StatementPatternNode sp : statementPatterns.values()) { final URI uri = (URI)(sp.p()).getValue(); if (!uris.add(uri)) throw new RuntimeException( "Search predicate appears multiple times for same search variable: predicate=" + uri + ", searchVar=" + searchVar); if (uri.equals(BDS.SEARCH)) { assertObjectIsLiteral(sp); } else if (uri.equals(BDS.RELEVANCE) || uri.equals(BDS.RANK)) { assertObjectIsVariable(sp); } else if(uri.equals(BDS.MIN_RANK)||uri.equals(BDS.MAX_RANK)) { assertObjectIsLiteral(sp); } else if (uri.equals(BDS.MIN_RELEVANCE) || uri.equals(BDS.MAX_RELEVANCE)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.MATCH_ALL_TERMS)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.MATCH_EXACT)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.SUBJECT_SEARCH)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.SEARCH_TIMEOUT)) { assertObjectIsLiteral(sp); } else if (uri.equals(BDS.RANGE_COUNT)) { assertObjectIsVariable(sp); } else if(uri.equals(BDS.MATCH_REGEX)) { // a variable for the object is equivalent to regex = null // assertObjectIsLiteral(sp); } else { throw new AssertionError("Unverified search predicate: " + sp); } } if (!uris.contains(BDS.SEARCH)) { throw new RuntimeException("Required search predicate not found: " + BDS.SEARCH + " for searchVar=" + searchVar); } }
Example 20
Source File: SearchInSearchServiceFactory.java From database with GNU General Public License v2.0 | 2 votes |
/** * Validate the search. There must be exactly one {@link BD#SEARCH} * predicate. There should not be duplicates of any of the search predicates * for a given searchVar. */ private void validateSearch(final IVariable<?> searchVar, final Map<URI, StatementPatternNode> statementPatterns) { final Set<URI> uris = new LinkedHashSet<URI>(); for(StatementPatternNode sp : statementPatterns.values()) { final URI uri = (URI)(sp.p()).getValue(); if (!uris.add(uri)) throw new RuntimeException( "Search predicate appears multiple times for same search variable: predicate=" + uri + ", searchVar=" + searchVar); if (uri.equals(BDS.SEARCH_IN_SEARCH)) { assertObjectIsLiteral(sp); } else if (uri.equals(BDS.RELEVANCE) || uri.equals(BDS.RANK)) { assertObjectIsVariable(sp); } else if(uri.equals(BDS.MIN_RANK) || uri.equals(BDS.MAX_RANK)) { assertObjectIsLiteral(sp); } else if (uri.equals(BDS.MIN_RELEVANCE) || uri.equals(BDS.MAX_RELEVANCE)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.MATCH_ALL_TERMS)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.MATCH_EXACT)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.SEARCH_TIMEOUT)) { assertObjectIsLiteral(sp); } else if(uri.equals(BDS.MATCH_REGEX)) { // a variable for the object is equivalent to regex = null // assertObjectIsLiteral(sp); } else { throw new AssertionError("Unverified search predicate: " + sp); } } if (!uris.contains(BDS.SEARCH_IN_SEARCH)) { throw new RuntimeException("Required search predicate not found: " + BDS.SUBJECT_SEARCH + " for searchVar=" + searchVar); } }