Search in sources :

Example 31 with LiteralLabel

use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.

the class Rational method testDateTime_9.

public void testDateTime_9() {
    // Years before 1000 : xsd:dateTime requires at least a four digit year.
    // GregorianCalendar does not handle negative years. (.get(YEAR) triggers
    // complete() which changes -77 into 78 (Java8)).
    int[] years = { 0, 7, 77, 777, 7777 };
    for (int y : years) {
        Calendar calM1 = Calendar.getInstance();
        calM1.set(Calendar.YEAR, y);
        calM1.set(Calendar.MONTH, 10);
        calM1.set(Calendar.DATE, 23);
        XSDDateTime xdtM = new XSDDateTime(calM1);
        LiteralLabel xdtM_ll = LiteralLabelFactory.createByValue(xdtM, "", XSDDatatype.XSDdateTime);
        assertTrue("Pre-1000 calendar value", xdtM_ll.isWellFormed());
        assertTrue("Pre-1000 calendar value", xdtM_ll.getLexicalForm().matches("^[0-9]{4}-.*"));
    }
    // Illegal dateTimes
    boolean ok = false;
    boolean old = JenaParameters.enableEagerLiteralValidation;
    try {
        JenaParameters.enableEagerLiteralValidation = true;
        Literal l1 = m.createTypedLiteral(new Date(12345656l), XSDDatatype.XSDdateTime);
    } catch (DatatypeFormatException e) {
        ok = true;
    } finally {
        JenaParameters.enableEagerLiteralValidation = old;
    }
    assertTrue("Early detection of invalid literals", ok);
}
Also used : DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) NodeFactory.createLiteral(org.apache.jena.graph.NodeFactory.createLiteral) LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Example 32 with LiteralLabel

use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.

the class TestTriple method testTripleEquals.

public void testTripleEquals() {
    // create some nodes to test
    BlankNodeId id = BlankNodeId.create();
    LiteralLabel L2 = LiteralLabelFactory.create(id.toString(), "", false);
    String U2 = id.toString();
    String N2 = id.toString();
    Node[] nodes = new Node[] { Node.ANY, NodeFactory.createBlankNode(id), NodeFactory.createBlankNode(), NodeFactory.createLiteral(L), NodeFactory.createLiteral(L2), NodeFactory.createURI(U), NodeFactory.createURI(U2), NodeFactory.createVariable(N), NodeFactory.createVariable(N2) };
    Triple[] triples = new Triple[nodes.length * nodes.length * nodes.length];
    for (int i = 0; i < nodes.length; i++) {
        for (int j = 0; j < nodes.length; j++) {
            for (int k = 0; k < nodes.length; k++) {
                triples[i * nodes.length * nodes.length + j * nodes.length + k] = new Triple(nodes[i], nodes[j], nodes[k]);
            }
        }
    }
    // set up the expected results matrix
    // a expected[i][j] is true if triples[i] equals triples[j]
    // triples are expected to be equals if there components are equal
    boolean[][] expected = new boolean[triples.length][triples.length];
    for (int i1 = 0; i1 < nodes.length; i1++) {
        for (int j1 = 0; j1 < nodes.length; j1++) {
            for (int k1 = 0; k1 < nodes.length; k1++) {
                for (int i2 = 0; i2 < nodes.length; i2++) {
                    for (int j2 = 0; j2 < nodes.length; j2++) {
                        for (int k2 = 0; k2 < nodes.length; k2++) {
                            expected[i1 * nodes.length * nodes.length + j1 * nodes.length + k1][i2 * nodes.length * nodes.length + j2 * nodes.length + k2] = nodes[i1].equals(nodes[i2]) && nodes[j1].equals(nodes[j2]) && nodes[k1].equals(nodes[k2]);
                        }
                    }
                }
            }
        }
    }
    assertEquals("triple, null", triples[0].equals(null), false);
    assertDiffer("triple, string", triples[0], "string");
    // now compare each triple with each other triple
    for (int i = 0; i < triples.length; i++) {
        for (int j = 0; j < triples.length; j++) {
            if (expected[i][j]) {
                assertEquals("triples " + i + ", " + j, triples[i], triples[j]);
            } else {
                assertDiffer("triples" + i + ", " + j, triples[i], triples[j]);
            }
        }
    }
}
Also used : BlankNodeId(org.apache.jena.graph.BlankNodeId) Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Example 33 with LiteralLabel

use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.

the class TestNode method eqTestCases.

/**
 *        test cases for equality: an array of (Node, String) pairs. [It's not worth
 *        making a special class for these pairs.] The nodes are created with caching
 *        off, to make sure that caching effects don't hide the effect of using .equals().
 *        The strings are "equality groups": the nodes should test equal iff their
 *        associated strings test equal.
 */
private Object[][] eqTestCases() {
    BlankNodeId id = BlankNodeId.create();
    LiteralLabel L2 = LiteralLabelFactory.create(id.toString(), "", false);
    LiteralLabel LLang1 = LiteralLabelFactory.createByValue("xyz", "en", null);
    LiteralLabel LLang2 = LiteralLabelFactory.createByValue("xyz", "EN", null);
    String U2 = id.toString();
    String N2 = id.toString();
    return new Object[][] { { Node.ANY, "0" }, { NodeFactory.createBlankNode(id), "1" }, { NodeFactory.createBlankNode(), "2" }, { NodeFactory.createBlankNode(id), "1" }, { NodeFactory.createLiteral(L), "3" }, { NodeFactory.createLiteral(L2), "4" }, { NodeFactory.createLiteral(L), "3" }, { NodeFactory.createURI(U), "5" }, { NodeFactory.createURI(U2), "6" }, { NodeFactory.createURI(U), "5" }, { NodeFactory.createVariable(N), "7" }, { NodeFactory.createVariable(N2), "8" }, { NodeFactory.createVariable(N), "7" }, { NodeFactory.createLiteral(LLang1), "9" }, { NodeFactory.createLiteral(LLang2), "10" } };
}
Also used : LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Example 34 with LiteralLabel

use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.

the class TestLiteralLabels method testHashCodesForBase64Binary_2.

public void testHashCodesForBase64Binary_2() {
    LiteralLabel A = node("'illgeal'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
    LiteralLabel B = node("'illgeal'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
    assertEquals(A.hashCode(), B.hashCode());
}
Also used : LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Example 35 with LiteralLabel

use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.

the class TestLiteralLabels method testHashCodesForBase64Binary_1.

public void testHashCodesForBase64Binary_1() {
    LiteralLabel A = node("'0123'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
    LiteralLabel B = node("'0123'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
    assertEquals(A.hashCode(), B.hashCode());
}
Also used : LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Aggregations

LiteralLabel (org.apache.jena.graph.impl.LiteralLabel)43 Node (org.apache.jena.graph.Node)8 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)7 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)5 NodeFactory.createLiteral (org.apache.jena.graph.NodeFactory.createLiteral)5 Test (org.junit.Test)5 RDFLangString (org.apache.jena.datatypes.xsd.impl.RDFLangString)4 BigDecimal (java.math.BigDecimal)3 BaseDatatype (org.apache.jena.datatypes.BaseDatatype)3 SpatialIndexException (org.apache.jena.query.spatial.SpatialIndexException)3 Var (org.apache.jena.sparql.core.Var)3 UUID (java.util.UUID)2 FrontsNode (org.apache.jena.graph.FrontsNode)2 Triple (org.apache.jena.graph.Triple)2 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 ExprVar (org.apache.jena.sparql.expr.ExprVar)2 FileReader (java.io.FileReader)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Duration (javax.xml.datatype.Duration)1