Package org.openrdf.model

Examples of org.openrdf.model.Literal


        NodeList titles = in.getElementsByTagName("title");
        // just one title is allowed.
        if (titles.getLength() == 1) {
            Node title = titles.item(0);
            String titleValue = title.getTextContent();
            Literal object;
            String lang = getLanguage(title);
            if (lang == null) {
                // unable to decide the language, leave it unknown
                object = RDFUtils.literal(titleValue);
            } else {
View Full Code Here


    ) {
        if (content.contains(":")) {
            // if it contains U+003A COLON, exit
            return;
        }
        Literal subject;
        if (language == null) {
            // ok, we don't know the language
            subject = RDFUtils.literal(content);
        } else {
            subject = RDFUtils.literal(content, language);
View Full Code Here

            String name,
            String content,
            String language,
            URI documentURI,
            ExtractionResult out) {
        Literal subject;
        if (language == null) {
            // ok, we don't know the language
            subject = RDFUtils.literal(content);
        } else {
            subject = RDFUtils.literal(content, language);
View Full Code Here

        }
    }

    @Test
    public void testCreateLiteralWithNullArgumentWorks() {
        Literal l;
        try {
            l = ValueFactoryImpl.getInstance().createLiteral((String) null);
        } catch (AssertionError ae) {
            // Expected when assertions are enabled.
            return;
        }
        assertNotNull(l);
        assertNull(l.stringValue());
        assertEquals(l, l);
    }
View Full Code Here

        parent.appendChild(eR);
      }
     
      else if (end instanceof Literal)
      {
        Literal l = (Literal)end;
        ValueFactory f = dataRepo.getValueFactory();
        URI r = f.createURI(l.getLabel());
        if (r == null)
          continue;
        Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
        parent.appendChild(eR);
      }
View Full Code Here

              eR = createResourceElement(fd, dataRepo, doc, sl, null, r, mqueryResults.get(value), Constants.DEFAULT_MAX_DEPTH, mres);
              parent.appendChild(eR);
            }
            else if (end instanceof Literal)
            {
              Literal l = (Literal)end;
              ValueFactory f = dataRepo.getValueFactory();
              URI r = f.createURI(l.getLabel());
              if (r == null)
                continue;
              Element eR;
              //serialize meta knowledge or not
              eR = createResourceElement(fd, dataRepo, doc, sl, null, r, mqueryResults.get(value), Constants.DEFAULT_MAX_DEPTH, mres);
              parent.appendChild(eR);
            }
            else if (end instanceof Statement)
            {
              String error = "Render Error: SPARQL query must end on node";
              throw new ParserConfigurationException(error);
            }
          }         
        }else{       
          //return values without metadata
          fr.inria.jfresnel.sparql.sesame.SPARQLSesameEvaluator fsse = new fr.inria.jfresnel.sparql.sesame.SPARQLSesameEvaluator();     
          fsse.setDataRepository(dataRepo);
          Vector queryResults = fsse.evaluateQuery(new SPARQLQuery(query));
          for (int k=0; k<queryResults.size(); k++) {
            Object end = queryResults.get(k);
            //resources++;
            if (end instanceof Resource)
            {
              Resource r = (Resource)end;
              Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
              parent.appendChild(eR);
            }
            else if (end instanceof Literal)
            {
              Literal l = (Literal)end;
              ValueFactory f = dataRepo.getValueFactory();
              URI r = f.createURI(l.getLabel());
              if (r == null)
                continue;
              Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
              parent.appendChild(eR);
            }
            else if (end instanceof Statement)
            {
              String error = "Render Error: SPARQL query must end on node";
              throw new ParserConfigurationException(error);
            }
          }
        }
      }
    }
    //still not extended to return results with metadata!
    else if (renderLens.getFSLInstanceDomains() != null)
    {
      System.out.println("Rendering getFSLInstanceDomains()...");
      FSLPath[] fid = renderLens.getFSLInstanceDomains();
      SesameLens sl = (SesameLens)renderLens;     
      FSLSesameEvaluator fse = new FSLSesameEvaluator();
      fse.setDataRepository(dataRepo);
      for (int i = 0; i < fid.length; i++)
      {
        //resources ++;
        Vector pathInstances = fse.evaluatePath(fid[i]);
        for (int k=0; k<pathInstances.size(); k++) {
        Object end = ((Vector)pathInstances.get(k)).get(0);
       
        if (end instanceof Resource)
        {
          Resource r = (Resource)end;
          Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);         
          parent.appendChild(eR);
        }
       
        else if (end instanceof Literal)
        {
          Literal l = (Literal)end;
          ValueFactory f = dataRepo.getValueFactory();
          URI r = f.createURI(l.getLabel());
          if (r == null)
            continue;
          Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
          parent.appendChild(eR);
        }
View Full Code Here

     * {@link Representation#get(String, String...)}).
     */
    @Test
    public void testPlainLiteralToTextConversion(){
        String field = "urn:test.RdfRepresentation:test.field";
        Literal noLangLiteral = valueFactory.getSesameFactory().createLiteral("A plain literal without Language");
        Literal enLiteral = valueFactory.getSesameFactory().createLiteral("An english literal","en");
        Literal deLiteral = valueFactory.getSesameFactory().createLiteral("Ein Deutsches Literal","de");
        Literal deATLiteral = valueFactory.getSesameFactory().createLiteral("Ein Topfen Verband hilft bei Zerrungen","de-AT");
        Collection<Literal> plainLiterals = Arrays.asList(noLangLiteral,enLiteral,deLiteral,deATLiteral);
        Representation rep = createRepresentation(null);
        rep.add(field, plainLiterals);
        //now test, that the Plain Literals are available as natural language
        //tests via the Representation Interface!
View Full Code Here

     * texts without language.
     */
    @Test
    public void testTypedLiteralToTextConversion(){
        String field = "urn:test.RdfRepresentation:test.field";
        Literal stringLiteral = valueFactory.getSesameFactory().createLiteral("This is a stirng value", XMLSchema.STRING);
        //also add an integer to test that other typed literals are not used as texts
        Literal integerLiteral = valueFactory.getSesameFactory().createLiteral(5);
        Representation rep = createRepresentation(null);
        rep.add(field, Arrays.asList(stringLiteral,integerLiteral));
        //test if the literal is returned when asking for natural language text without language
        Iterator<Text> noLangTexts = rep.get(field, (String)null);
        assertTrue(noLangTexts.hasNext());
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testTypedLiteralToValueConversion(){
        String field = "urn:test.RdfRepresentation:test.field";
        Integer integerValue = 5;
        Literal integerLiteral = valueFactory.getSesameFactory().createLiteral(integerValue);
        Date dateValue = new Date();
        Literal dateLiteeral = valueFactory.getSesameFactory().createLiteral(dateValue);
        Double doubleValue = Math.PI;
        Literal doubleLiteral = valueFactory.getSesameFactory().createLiteral(doubleValue);
        String stringValue = "This is a string literal value";
        Literal stringLiteral = valueFactory.getSesameFactory().createLiteral(stringValue,XMLSchema.STRING);
        Representation rep = createRepresentation(null);
        Collection<Literal> typedLiterals =
            Arrays.asList(integerLiteral,doubleLiteral,stringLiteral,dateLiteeral);
        rep.add(field, typedLiterals);
       
        //now check that such values are available via Sesame Literal
        Iterator<Literal> typedLiteralValues = rep.get(field, Literal.class);
        int size = 0;
        while(typedLiteralValues.hasNext()){
            Literal next = typedLiteralValues.next();
            assertTrue(typedLiterals.contains(next));
            size++;
        }
        assertTrue(typedLiterals.size() == size);
       
View Full Code Here

        if(sesameType != null){
            return sesameType.isAssignableFrom(object.getClass());
        } else if(referenceState && object instanceof URI || object instanceof BNode){
            return true;
        } else if(object instanceof Literal){
            Literal literal = (Literal)object;
            //TODO: adapt to RDF1.1:
            if(plainLiteralState && ( literal.getDatatype() == null ||
                    XMLSchema.STRING.equals(literal.getDatatype())) && (
                    languages == null || languages.contains(literal.getLanguage()))){
                return true;
            } else if(!plainLiteralState && xmlTypes != null && literal.getDatatype() != null){
                return xmlTypes.contains(literal.getDatatype());
            } else { //wrong literal type
                return false;
            }
        } else { //wrong Value type or not a Value at all
            return false;
View Full Code Here

TOP

Related Classes of org.openrdf.model.Literal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.