Java Code Examples for org.eclipse.rdf4j.model.vocabulary.RDF#LANGSTRING

The following examples show how to use org.eclipse.rdf4j.model.vocabulary.RDF#LANGSTRING . 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: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Value evaluate(Datatype node, BindingSet bindings)
		throws QueryEvaluationException {
	Value v = evaluate(node.getArg(), bindings);

	if (v instanceof Literal) {
		Literal literal = (Literal) v;

		if (literal.getDatatype() != null) {
			// literal with datatype
			return literal.getDatatype();
		} else if (literal.getLanguage().isPresent()) {
			return RDF.LANGSTRING;
		} else {
			// simple literal
			return XMLSchema.STRING;
		}

	}

	throw new ValueExprEvaluationException();
}
 
Example 2
Source File: HalyardValueExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate a {@link Datatype} node
 * @param node the node to evaluate
 * @param bindings the set of named value bindings
 * @return a {@link Literal} representing the evaluation of the argument of the {@link Datatype}.
 * @throws ValueExprEvaluationException
 * @throws QueryEvaluationException
 */
private Value evaluate(Datatype node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException {
    Value v = evaluate(node.getArg(), bindings);
    if (v instanceof Literal) {
        Literal literal = (Literal) v;
        if (literal.getDatatype() != null) {
            // literal with datatype
            return literal.getDatatype();
        } else if (literal.getLanguage() != null) {
            return RDF.LANGSTRING;
        } else {
            // simple literal
            return XMLSchema.STRING;
        }
    }
    throw new ValueExprEvaluationException();
}
 
Example 3
Source File: RyaToRdfConversionsTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertLiteral_validLanguage() {
    final String expectedData = "Hello";
    for (final String language : LANGUAGE_CODES) {
        // This only checks the validity of the format. Not that the language tag actually exists.
        assertTrue(Literals.isValidLanguageTag(language));
        final RyaType ryaType = new RyaType(RDF.LANGSTRING, expectedData, language);
        final Literal literal = RyaToRdfConversions.convertLiteral(ryaType);
        assertEquals(RDF.LANGSTRING, literal.getDatatype());
        assertEquals(expectedData, literal.getLabel());
        assertTrue(literal.getLanguage().isPresent());
        assertEquals(language, literal.getLanguage().get());
        final Literal expectedLiteral = VF.createLiteral(expectedData, language);
        assertEquals(expectedLiteral, literal);
    }
}
 
Example 4
Source File: RyaToRdfConversionsTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertLiteral_invalidLanguage() {
    final String expectedData = "Hello";
    final List<String> badLanguages = Lists.newArrayList(
            "bad language",
            "en-",
            "en-US-"
    );
    for (final String badLanguage : badLanguages) {
        // This only checks the validity of the format. Not that the language tag actually exists.
        assertFalse(Literals.isValidLanguageTag(badLanguage));
        final RyaType ryaType = new RyaType(RDF.LANGSTRING, expectedData, badLanguage);
        final Literal literal = RyaToRdfConversions.convertLiteral(ryaType);
        assertEquals(RDF.LANGSTRING, literal.getDatatype());
        assertEquals(expectedData, literal.getLabel());
        assertTrue(literal.getLanguage().isPresent());
        // Check that the invalid language is replaced with "und"
        assertEquals(LiteralLanguageUtils.UNDETERMINED_LANGUAGE, literal.getLanguage().get());
    }
}
 
Example 5
Source File: SimpleLiteralTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.impl.SimpleLiteral#SimpleLiteral(java.lang.String, org.eclipse.rdf4j.model.IRI)} .
 */
@Test
public final void testStringIRINullLangString() throws Exception {
	String label = null;
	IRI datatype = RDF.LANGSTRING;

	thrown.expect(NullPointerException.class);
	new SimpleLiteral(label, datatype);
}
 
Example 6
Source File: SimpleLiteralTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.impl.SimpleLiteral#SimpleLiteral(java.lang.String, org.eclipse.rdf4j.model.IRI)} .
 */
@Test
public final void testStringIRIEmptyLangString() throws Exception {
	String label = "";
	IRI datatype = RDF.LANGSTRING;

	thrown.expect(IllegalArgumentException.class);
	new SimpleLiteral(label, datatype);
}
 
Example 7
Source File: RyaToRdfConversionsTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertLiteral_undeterminedLanguage() {
    final String expectedData = "Hello";
    final String language = LiteralLanguageUtils.UNDETERMINED_LANGUAGE;
    assertTrue(Literals.isValidLanguageTag(language));
    final RyaType ryaType = new RyaType(RDF.LANGSTRING, expectedData, language);
    final Literal literal = RyaToRdfConversions.convertLiteral(ryaType);
    assertEquals(RDF.LANGSTRING, literal.getDatatype());
    assertEquals(expectedData, literal.getLabel());
    assertTrue(literal.getLanguage().isPresent());
    assertEquals(LiteralLanguageUtils.UNDETERMINED_LANGUAGE, literal.getLanguage().get());
    final Literal expectedLiteral = VF.createLiteral(expectedData, language);
    assertEquals(expectedLiteral, literal);
}
 
Example 8
Source File: RdfToRyaConversionsTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertLiteral_validLanguage() {
    final String expectedData = "Hello";
    for (final String language : LANGUAGE_CODES) {
        // This only checks the validity of the format. Not that the language tag actually exists.
        assertTrue(Literals.isValidLanguageTag(language));
        final Literal literal = VF.createLiteral(expectedData, language);
        final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal);
        assertEquals(RDF.LANGSTRING, ryaType.getDataType());
        assertEquals(expectedData, ryaType.getData());
        assertEquals(language, ryaType.getLanguage());
        final RyaType expectedRyaType = new RyaType(RDF.LANGSTRING, expectedData, language);
        assertEquals(expectedRyaType, ryaType);
    }
}
 
Example 9
Source File: RdfToRyaConversionsTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertLiteral_undeterminedLanguage() {
    final String expectedData = "Hello";
    final String language = LiteralLanguageUtils.UNDETERMINED_LANGUAGE;
    assertTrue(Literals.isValidLanguageTag(language));
    final Literal literal = VF.createLiteral(expectedData, language);
    final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal);
    assertEquals(RDF.LANGSTRING, ryaType.getDataType());
    assertEquals(expectedData, ryaType.getData());
    final RyaType expectedRyaType = new RyaType(RDF.LANGSTRING, expectedData, language);
    assertEquals(expectedRyaType, ryaType);
    assertEquals(LiteralLanguageUtils.UNDETERMINED_LANGUAGE, ryaType.getLanguage());
}
 
Example 10
Source File: RDFLangStringDatatypeHandlerTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected IRI getRecognisedDatatypeUri() {
	return RDF.LANGSTRING;
}
 
Example 11
Source File: XMLSchemaDoubleDatatypeHandlerTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected IRI getUnrecognisedDatatypeUri() {
	return RDF.LANGSTRING;
}
 
Example 12
Source File: VirtuosoGeometryPointDatatypeHandlerTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected IRI getUnrecognisedDatatypeUri() {
	return RDF.LANGSTRING;
}