Java Code Examples for com.hp.hpl.jena.rdf.model.RDFNode#isAnon()

The following examples show how to use com.hp.hpl.jena.rdf.model.RDFNode#isAnon() . 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: PlainTextMessageRenderer.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
private String nodeType(RDFNode node) {
	if (node.isURIResource()) {
		return "IRI";
	}
	if (node.isAnon()) {
		return "blank node";
	}
	if (!"".equals(node.asLiteral().getLanguage())) {
		return "language-tagged string";
	}
	if (node.asLiteral().getDatatypeURI() == null) {
		return "plain literal";
	}
	if (XSD.xstring.getURI().equals(node.asLiteral().getDatatypeURI())) {
		return "string literal";
	}
	return "non-string typed literal";
}
 
Example 2
Source File: RDFComparator.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
public int compare(RDFNode n1, RDFNode n2) {
	if (n1.isURIResource()) {
		if (!n2.isURIResource()) return -1;
		return n1.asResource().getURI().compareTo(n2.asResource().getURI());
	}
	if (n1.isAnon()) {
		if (n2.isURIResource()) return 1;
		if (n2.isLiteral()) return -1;
		return n1.asResource().getId().getLabelString().compareTo(n2.asResource().getId().getLabelString());
	}
	if (!n2.isLiteral()) return 1;
	int cmpLex = n1.asLiteral().getLexicalForm().compareTo(n2.asLiteral().getLexicalForm());
	if (cmpLex != 0) return cmpLex;
	if (n1.asLiteral().getDatatypeURI() == null) {
		if (n2.asLiteral().getDatatypeURI() != null) return -1;
		return n1.asLiteral().getLanguage().compareTo(n2.asLiteral().getLanguage());
	}
	if (n2.asLiteral().getDatatypeURI() == null) return 1;
	return n1.asLiteral().getDatatypeURI().compareTo(n2.asLiteral().getDatatypeURI()); 
}
 
Example 3
Source File: RDFReader.java    From marklogic-contentpump with Apache License 2.0 5 votes vote down vote up
private String object(RDFNode node) {
    if (node.isLiteral()) {
        Literal lit = node.asLiteral();
        String text = lit.getString();
        String lang = lit.getLanguage();
        String type = lit.getDatatypeURI();

        if (lang == null || "".equals(lang)) {
            lang = "";
        } else {
            lang = " xml:lang='" + escapeXml(lang) + "'";
        }

        if ("".equals(lang)) {
            if (type == null) {
                type = "http://www.w3.org/2001/XMLSchema#string";
            }
            type = " datatype='" + escapeXml(type) + "'";
        } else {
            type = "";
        }

        return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>";
    } else if (node.isAnon()) {
        return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString(
                hash64(fuse(scramble(milliSecs),randomValue), node.toString()))
                +"</sem:object>";
    } else {
        return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>";
    }
}
 
Example 4
Source File: R2RMLReader.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public RDFNode coerce(RDFNode in) {
	if (in.isAnon()) return null;
	if (in.isURIResource()) {
		return ResourceFactory.createPlainLiteral(in.asResource().getURI());
	}
	return ResourceFactory.createPlainLiteral(in.asLiteral().getLexicalForm());
}
 
Example 5
Source File: R2RMLReader.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public RDFNode coerce(RDFNode in) {
	return in.isAnon() ? null : in;
}
 
Example 6
Source File: R2RMLReader.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public boolean isTypeOf(RDFNode node) {
	return (node.isURIResource() || node.isAnon());
}