Search in sources :

Example 16 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class Rational method testRDFLangString_1.

public void testRDFLangString_1() {
    // Registration
    RDFDatatype dt = TypeMapper.getInstance().getTypeByName(RDF.langString.getURI());
    assertEquals(RDF.dtLangString, dt);
    assertTrue(RDF.dtLangString == dt);
}
Also used : RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 17 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class JenaReader method convert.

private static Node convert(ALiteral lit) {
    String dtURI = lit.getDatatypeURI();
    if (dtURI == null)
        return NodeFactory.createLiteral(lit.toString(), lit.getLang());
    if (lit.isWellFormedXML()) {
        return NodeFactory.createLiteral(lit.toString(), null, true);
    }
    RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(dtURI);
    return NodeFactory.createLiteral(lit.toString(), dt);
}
Also used : RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 18 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class NodeFactoryExtra method createLiteralNode.

/** Create a literal Node, when the datatype, if given, is a string */
public static Node createLiteralNode(String lex, String lang, String datatypeURI) {
    if (datatypeURI != null && datatypeURI.equals(""))
        datatypeURI = null;
    if (lang != null && lang.equals(""))
        lang = null;
    RDFDatatype dType = null;
    if (datatypeURI != null)
        dType = TypeMapper.getInstance().getSafeTypeByName(datatypeURI);
    Node n = NodeFactory.createLiteral(lex, lang, dType);
    return n;
}
Also used : Node(org.apache.jena.graph.Node) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 19 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class TextQueryPF method objectToStruct.

/** Deconstruct the node or list object argument and make a StrMatch 
     * The 'executionTime' flag indciates whether this is for a build time
     * static check, or for runtime execution.
     */
private StrMatch objectToStruct(PropFuncArg argObject, boolean executionTime) {
    EntityDefinition docDef = textIndex.getDocDef();
    if (argObject.isNode()) {
        Node o = argObject.getArg();
        if (!o.isLiteral()) {
            if (executionTime)
                log.warn("Object to text query is not a literal");
            return null;
        }
        RDFDatatype dt = o.getLiteralDatatype();
        if (dt != null && dt != XSDDatatype.XSDstring) {
            log.warn("Object to text query is not a string");
            return null;
        }
        String qs = o.getLiteralLexicalForm();
        return new StrMatch(null, qs, null, -1, 0);
    }
    List<Node> list = argObject.getArgList();
    if (list.size() == 0 || list.size() > 4)
        throw new TextIndexException("Change in object list size");
    Node predicate = null;
    // Do not prepend the field name - rely on default field
    String field = null;
    int idx = 0;
    Node x = list.get(0);
    // Property?
    if (x.isURI()) {
        predicate = x;
        idx++;
        if (idx >= list.size())
            throw new TextIndexException("Property specificed but no query string : " + list);
        x = list.get(idx);
        field = docDef.getField(predicate);
        if (field == null) {
            log.warn("Predicate not indexed: " + predicate);
            return null;
        }
    }
    // String!
    if (!x.isLiteral()) {
        if (executionTime)
            log.warn("Text query string is not a literal " + list);
        return null;
    }
    if (x.getLiteralDatatype() != null && !x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
        log.warn("Text query is not a string " + list);
        return null;
    }
    String queryString = x.getLiteralLexicalForm();
    idx++;
    int limit = -1;
    float score = 0;
    if (idx < list.size()) {
        // Limit?
        x = list.get(idx);
        idx++;
        if (!x.isLiteral()) {
            if (executionTime)
                log.warn("Text query limit is not an integer " + x);
            return null;
        }
        int v = NodeFactoryExtra.nodeToInt(x);
        limit = (v < 0) ? -1 : v;
    }
    //extract extra lang arg if present and if is usable.
    String lang = extractArg("lang", list);
    if (lang != null && textIndex.getDocDef().getLangField() == null)
        log.warn("lang argument is ignored if langField not set in the index configuration");
    return new StrMatch(predicate, queryString, lang, limit, score);
}
Also used : Node(org.apache.jena.graph.Node) RDFDatatype(org.apache.jena.datatypes.RDFDatatype)

Example 20 with RDFDatatype

use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.

the class FBRuleInfGraph method checkLiteral.

/**
     * Check a given literal value for a property against the set of
     * known range constraints for it.
     * @param prop the property node whose range is under scrutiny
     * @param triple the statement whose object value is to be checked.
     * @return null if the range is legal, otherwise a ValidityReport.Report
     * which describes the problem.
     */
public ValidityReport.Report checkLiteral(Node prop, Triple triple) {
    Node value = triple.getObject();
    List<RDFDatatype> range = getDTRange().get(prop);
    if (range != null) {
        if (value.isBlank())
            return null;
        if (!value.isLiteral()) {
            return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value);
        }
        LiteralLabel ll = value.getLiteral();
        for (RDFDatatype dt : range) {
            if (!dt.isValidLiteral(ll)) {
                return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range " + dt + "that is not compatible with " + value, triple);
            }
        }
    }
    return null;
}
Also used : RDFNode(org.apache.jena.rdf.model.RDFNode) RDFDatatype(org.apache.jena.datatypes.RDFDatatype) LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Aggregations

RDFDatatype (org.apache.jena.datatypes.RDFDatatype)35 Node (org.apache.jena.graph.Node)9 LiteralLabel (org.apache.jena.graph.impl.LiteralLabel)6 TypeMapper (org.apache.jena.datatypes.TypeMapper)4 RDFLangString (org.apache.jena.datatypes.xsd.impl.RDFLangString)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)2 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 FileReader (java.io.FileReader)1 Duration (javax.xml.datatype.Duration)1 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 BaseDatatype (org.apache.jena.datatypes.BaseDatatype)1 XSDDateTime (org.apache.jena.datatypes.xsd.XSDDateTime)1 EnhNode (org.apache.jena.enhanced.EnhNode)1 RiotException (org.apache.jena.riot.RiotException)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1 Token (org.apache.jena.riot.tokens.Token)1 Item (org.apache.jena.sparql.sse.Item)1