use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class TestLiteralLabels method testDatatypeIsEqualsNotCalledIfSecondOperandIsNotTyped.
public void testDatatypeIsEqualsNotCalledIfSecondOperandIsNotTyped() {
RDFDatatype d = new BaseDatatype("eh:/FakeDataType") {
@Override
public boolean isEqual(LiteralLabel A, LiteralLabel B) {
fail("RDFDatatype::isEquals should not be called if B has no datatype");
return false;
}
};
LiteralLabel A = LiteralLabelFactory.createByValue("17", "", d);
LiteralLabel B = LiteralLabelFactory.createByValue("17", "", null);
assertFalse(A.sameValueAs(B));
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class ParseHandlerPlain method emitLiteral.
@Override
public void emitLiteral(int line, int column, String lexicalForm, String langTag, String datatypeIRI, String datatypePN) {
Node n = null;
if (datatypeIRI != null || datatypePN != null) {
if (datatypePN != null)
datatypeIRI = resolvePrefixedName(datatypePN, line, column);
RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(datatypeIRI);
n = NodeFactory.createLiteral(lexicalForm, dType);
} else
n = NodeFactory.createLiteral(lexicalForm, langTag);
Item item = Item.createNode(n, line, column);
listAdd(item);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class Rational method testDateTimeBug.
/**
* Test a user error report concerning date/time literals
*/
public void testDateTimeBug() {
// Bug in serialization
String XSDDateURI = XSD.date.getURI();
TypeMapper typeMapper = TypeMapper.getInstance();
RDFDatatype dt = typeMapper.getSafeTypeByName(XSDDateURI);
Object obj = dt.parse("2003-05-21");
Literal literal = m.createTypedLiteral(obj, dt);
literal.toString();
Object value2 = dt.parse(obj.toString());
assertEquals(obj, value2);
// Check alternative form doesn't provoke exceptions
RDFDatatype dateType = XSDDatatype.XSDdate;
m.createTypedLiteral("2003-05-21", dateType);
// Check alt time times
checkSerialization("2003-05-21", XSDDatatype.XSDdate);
checkSerialization("2003-05-21T12:56:10Z", XSDDatatype.XSDdateTime);
checkSerialization("2003-05", XSDDatatype.XSDgYearMonth);
checkSerialization("2003", XSDDatatype.XSDgYear);
checkSerialization("--05", XSDDatatype.XSDgMonth);
checkSerialization("--05-12", XSDDatatype.XSDgMonthDay);
checkSerialization("---12", XSDDatatype.XSDgDay);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class Rational method testUserDefined.
/**
* Test user defined data types.
* This is based on a corrected, modified version of an early DAML+OIL example
* but is not specific to DAML+OIL.
*/
public void testUserDefined() throws IOException {
String uri = "http://www.daml.org/2001/03/daml+oil-ex-dt";
String filename = "testing/xsd/daml+oil-ex-dt.xsd";
TypeMapper tm = TypeMapper.getInstance();
List<String> typenames = XSDDatatype.loadUserDefined(uri, new FileReader(filename), null, tm);
assertIteratorValues(typenames.iterator(), new Object[] { uri + "#XSDEnumerationHeight", uri + "#over12", uri + "#over17", uri + "#over59", uri + "#clothingsize" });
// Check the string restriction
RDFDatatype heightType = tm.getSafeTypeByName(uri + "#XSDEnumerationHeight");
checkLegalLiteral("short", heightType, String.class, "short");
checkLegalLiteral("tall", heightType, String.class, "tall");
checkIllegalLiteral("shortish", heightType);
// Check the numeric restriction
RDFDatatype over12Type = tm.getSafeTypeByName(uri + "#over12");
checkLegalLiteral("15", over12Type, Integer.class, 15);
checkIllegalLiteral("12", over12Type);
// Check the union type
RDFDatatype clothingsize = tm.getSafeTypeByName(uri + "#clothingsize");
checkLegalLiteral("42", clothingsize, Integer.class, 42);
checkLegalLiteral("short", clothingsize, String.class, "short");
// Check use of isValidLiteral for base versus derived combinations
LiteralLabel iOver12 = m.createTypedLiteral("13", over12Type).asNode().getLiteral();
LiteralLabel iDecimal14 = m.createTypedLiteral("14", XSDDatatype.XSDdecimal).asNode().getLiteral();
LiteralLabel iDecimal10 = m.createTypedLiteral("10", XSDDatatype.XSDdecimal).asNode().getLiteral();
LiteralLabel iString = m.createTypedLiteral("15", XSDDatatype.XSDstring).asNode().getLiteral();
LiteralLabel iPlain = m.createLiteral("foo").asNode().getLiteral();
assertTrue(over12Type.isValidLiteral(iOver12));
assertTrue(over12Type.isValidLiteral(iDecimal14));
assertTrue(!over12Type.isValidLiteral(iDecimal10));
assertTrue(!over12Type.isValidLiteral(iString));
assertTrue(!over12Type.isValidLiteral(iPlain));
assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(iOver12));
assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(iDecimal14));
assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(iDecimal10));
assertTrue(!XSDDatatype.XSDdecimal.isValidLiteral(iString));
assertTrue(!XSDDatatype.XSDdecimal.isValidLiteral(iPlain));
assertTrue(XSDDatatype.XSDstring.isValidLiteral(iString));
assertTrue(XSDDatatype.XSDstring.isValidLiteral(iPlain));
assertTrue(!XSDDatatype.XSDstring.isValidLiteral(iOver12));
assertTrue(!XSDDatatype.XSDstring.isValidLiteral(iDecimal10));
assertTrue(!XSDDatatype.XSDstring.isValidLiteral(iDecimal14));
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class Rational method testDecimalFind.
/**
* Test case for a bug in retrieving a value like 3.00 from
* a probe like 3.0
*/
public void testDecimalFind() {
RDFDatatype dt = XSDDatatype.XSDdecimal;
Node ns = NodeFactory.createURI("x");
Node np = NodeFactory.createURI("p");
Node nx1 = NodeFactory.createLiteral("0.50", dt);
Node nx2 = NodeFactory.createLiteral("0.500", dt);
Graph graph = Factory.createDefaultGraph();
graph.add(new Triple(ns, np, nx1));
assertTrue(graph.find(Node.ANY, Node.ANY, nx2).hasNext());
}
Aggregations