use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class ParserBase method stripSign.
protected Node stripSign(Node node) {
if (!node.isLiteral())
return node;
String lex = node.getLiteralLexicalForm();
String lang = node.getLiteralLanguage();
RDFDatatype dt = node.getLiteralDatatype();
if (!lex.startsWith("-") && !lex.startsWith("+"))
throw new ARQInternalErrorException("Literal does not start with a sign: " + lex);
lex = lex.substring(1);
return NodeFactory.createLiteral(lex, lang, dt);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class Rational method testUserDef.
/**
* Tests the base functioning of a user defined datatype
*/
public void testUserDef() {
// Register the user defined type for rationals
RDFDatatype rtype = RationalType.theRationalType;
TypeMapper.getInstance().registerDatatype(rtype);
Literal l1 = m.createTypedLiteral("3/5", rtype);
Literal l3 = m.createTypedLiteral("7/5", rtype);
// Check for successful creation
assertNotNull(l1);
assertNotNull(l3);
// check equality function
assertDiffer("values should be tested!", l1, l3);
// Check typed accessors
assertSame("Datatype incorrect", l1.getDatatype(), rtype);
assertEquals("Datatype uri incorrect", l1.getDatatypeURI(), RationalType.theTypeURI);
Object val = l1.getValue();
assertTrue("Value space check", val instanceof Rational);
assertTrue("Value check", ((Rational) val).getNumerator() == 3);
assertTrue("Value check", ((Rational) val).getDenominator() == 5);
try {
l1.getInt();
assertTrue("Allowed int conversion", false);
} catch (DatatypeFormatException e) {
}
assertEquals("Extract xml tag", l1.isWellFormedXML(), false);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class TestNode method assertString.
private static void assertString(Node n) {
RDFDatatype dt = n.getLiteralDatatype();
assertEquals("", n.getLiteralLanguage());
if (JenaRuntime.isRDF11)
assertEquals(XSDDatatype.XSDstring, dt);
else
assertEquals(null, dt);
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class TestNode method testLiteralToString.
public void testLiteralToString() {
TypeMapper tm = TypeMapper.getInstance();
RDFDatatype dtInt = tm.getTypeByValue(new Integer(10));
Node plain = NodeFactory.createLiteral("rhubarb", "");
Node english = NodeFactory.createLiteral("eccentric", "en_UK");
Node typed = NodeFactory.createLiteral("10", dtInt);
assertEquals("\"rhubarb\"", plain.toString());
assertEquals("rhubarb", plain.toString(false));
assertEquals("\"eccentric\"@en_UK", english.toString());
assertEquals("10^^http://www.w3.org/2001/XMLSchema#int", typed.toString(false));
}
use of org.apache.jena.datatypes.RDFDatatype in project jena by apache.
the class TestNode method testDataMatches.
public void testDataMatches() {
TypeMapper tm = TypeMapper.getInstance();
RDFDatatype dt1 = tm.getTypeByValue(new Integer(10));
RDFDatatype dt2 = tm.getTypeByValue(new Short((short) 10));
Node a = NodeFactory.createLiteral("10", dt1);
Node b = NodeFactory.createLiteral("10", dt2);
assertDiffer("types must make a difference", a, b);
assertTrue("A and B must express the same value", a.sameValueAs(b));
assertTrue("matching literals must respect sameValueAs", a.matches(b));
}
Aggregations