Java Code Examples for org.openrdf.model.URI#toString()

The following examples show how to use org.openrdf.model.URI#toString() . 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: ValidatedTransaction.java    From anno4j with Apache License 2.0 6 votes vote down vote up
/**
 * Returns all resources that exist in a specific context.
 * @param context The context from which to get resources.
 * @return All resources (IRIs) that are present in {@code context}.
 * @throws RepositoryException Thrown if an error occurs while querying the repository.
 */
private Set<ResourceObject> getResourcesFromContext(URI context) throws RepositoryException {
    try {
        String q = QUERY_PREFIX + "SELECT ?o " +
                "FROM NAMED <" + context.toString() + "> " +
                "{" +
                "   GRAPH <" + context.toString() + "> {" +
                "       { ?o ?p ?x . } UNION { ?x ?p ?o . }" +
                "       FILTER ( isIRI(?o) )" +
                "   }" +
                "}";

        Set<ResourceObject> resources = new HashSet<>();
        for (Object current : getConnection().prepareObjectQuery(q).evaluate().asSet()) {
            if(current instanceof ResourceObject) {
                resources.add((ResourceObject) current);
            }
        }

        return resources;

    } catch (QueryEvaluationException | MalformedQueryException e) {
        throw new RepositoryException(e);
    }
}
 
Example 2
Source File: XMLGregorianCalendarMarshall.java    From anno4j with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleX1()
	throws SailException
{
	int nofInferred = 0;

	String prefix = RDF.NAMESPACE + "_";
	Iterator<Statement> iter = this.newThisIteration.match(null, null, null);

	while (iter.hasNext()) {
		Statement st = iter.next();

		URI predNode = st.getPredicate();
		String predURI = predNode.toString();

		if (predURI.startsWith(prefix) && isValidPredicateNumber(predURI.substring(prefix.length()))) {
			boolean added = addInferredStatement(predNode, RDF.TYPE, RDFS.CONTAINERMEMBERSHIPPROPERTY);
			if (added) {
				nofInferred++;
			}
		}
	}

	return nofInferred;
}
 
Example 4
Source File: SPARQLQueryTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected void upload(URI graphURI, Resource context)
	throws Exception
{
	RepositoryConnection con = dataRep.getConnection();

	try {
		con.begin();
		RDFFormat rdfFormat = Rio.getParserFormatForFileName(graphURI.toString(), RDFFormat.TURTLE);
		RDFParser rdfParser = Rio.createParser(rdfFormat, dataRep.getValueFactory());
		rdfParser.setVerifyData(false);
		rdfParser.setDatatypeHandling(DatatypeHandling.IGNORE);
		// rdfParser.setPreserveBNodeIDs(true);

		RDFInserter rdfInserter = new RDFInserter(con);
		rdfInserter.enforceContext(context);
		rdfParser.setRDFHandler(rdfInserter);

		URL graphURL = new URL(graphURI.toString());
		InputStream in = graphURL.openStream();
		try {
			rdfParser.parse(in, graphURI.toString());
		}
		finally {
			in.close();
		}

		con.commit();
	}
	catch (Exception e) {
		if (con.isActive()) {
			con.rollback();
		}
		throw e;
	}
	finally {
		con.close();
	}
}
 
Example 5
Source File: IntegerMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.INT))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 6
Source File: DoubleMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.DOUBLE))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 7
Source File: ByteMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.BYTE))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 8
Source File: BigIntegerMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI dt) {
	if (!dt.equals(datatype))
		throw new IllegalArgumentException(dt.toString());
}
 
Example 9
Source File: LongMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.LONG))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 10
Source File: BigDecimalMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI dt) {
	if (!dt.equals(datatype))
		throw new IllegalArgumentException(dt.toString());
}
 
Example 11
Source File: FloatMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.FLOAT))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 12
Source File: QNameMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.QNAME))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 13
Source File: BooleanMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.BOOLEAN))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 14
Source File: ShortMarshall.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setDatatype(URI datatype) {
	if (!datatype.equals(XMLSchema.SHORT))
		throw new IllegalArgumentException(datatype.toString());
}
 
Example 15
Source File: AbstractTripleStore.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Substitutes in well know namespaces (rdf, rdfs, etc).
 */
final private String abbrev(final URI uri) {

    final String uriString = uri.toString();

    // final int index = uriString.lastIndexOf('#');
    //        
    // if(index==-1) return uriString;
    //
    // final String namespace = uriString.substring(0, index);

    final String namespace = uri.getNamespace();

    final String prefix = uriToPrefix.get(namespace);

    if (prefix != null) {

        return prefix + ":" + uri.getLocalName();

    }
    
    return uriString;

}
 
Example 16
Source File: LexiconKeyBuilder.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return an unsigned byte[] that locates the value within a total ordering
 * over the RDF value space.
 * 
 * @param value
 *            An RDF value.
 * 
 * @return The sort key for that RDF value.
 */
public byte[] value2Key(final Value value) {

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

    if (value instanceof URI) {

        final URI uri = (URI) value;

        final String term = uri.toString();

        return uri2key(term);

    } else if (value instanceof Literal) {

        final Literal lit = (Literal) value;

        final String text = lit.getLabel();

        final String languageCode = lit.getLanguage();

        final URI datatypeUri = lit.getDatatype();

        if (languageCode != null) {

            /*
             * language code literal.
             */
            return languageCodeLiteral2key(languageCode, text);

        } else if (datatypeUri != null) {

            /*
             * datatype literal.
             */
            return datatypeLiteral2key(datatypeUri, text);

        } else {

            /*
             * plain literal.
             */
            return plainLiteral2key(text);

        }

    } else if (value instanceof BNode) {

        /*
         * @todo if we know that the bnode id is a UUID that we generated
         * then we should encode that using faster logic that this unicode
         * conversion and stick the sort key on the bnode so that we do not
         * have to convert UUID to id:String to key:byte[].
         */
        final String bnodeId = ((BNode) value).getID();

        return blankNode2Key(bnodeId);

    } else {

        throw new AssertionError("Unknown value type: " + value.getClass());

    }

}