Package org.openrdf.model

Examples of org.openrdf.model.ValueFactory


  {
    Form params = getQuery();
    int amount = ServerUtil.parseIntegerParam(params, Protocol.AMOUNT, 1);
    String nodeID = params.getFirstValue(Protocol.NODE_ID);

    ValueFactory vf = getConnection().getValueFactory();

    List<String> columns = Arrays.asList(Protocol.BNODE);
    List<BindingSet> bnodes = new ArrayList<BindingSet>(amount);
    for (int i = 0; i < amount; i++) {
      BNode bnode = createBNode(vf, nodeID, i);
View Full Code Here


    @Test
    public void testLinkExtraction() throws RepositoryException {
        assertExtract("/html/html-head-link-extractor.html");
        assertModelNotEmpty();
        final ValueFactory valueFactory = new ValueFactoryImpl();
        final URI externalLinkURI = valueFactory.createURI("http://www.myexperiment.org/workflows/16.rdf");
        assertContains(
                AbstractExtractorTestCase.baseURI,
                valueFactory.createURI("http://www.w3.org/1999/xhtml/vocab#alternate"),
                externalLinkURI

        );
        assertContains(
                externalLinkURI,
                valueFactory.createURI("http://purl.org/dc/terms/title"),
                valueFactory.createLiteral("RDF+XML")

        );
        assertContains(
                externalLinkURI,
                valueFactory.createURI("http://purl.org/dc/terms/format"),
                valueFactory.createLiteral("application/rdf+xml")

        );
    }
View Full Code Here

  }

  @Override
  public Resource export(Graph graph) {
    Resource implNode = super.export(graph);
    ValueFactory vf = graph.getValueFactory();

    if (tripleIndexes != null) {
      graph.add(implNode, TRIPLE_INDEXES, vf.createLiteral(tripleIndexes));
    }
    if (forceSync) {
      graph.add(implNode, FORCE_SYNC, vf.createLiteral(forceSync));
    }
    if (valueCacheSize >= 0) {
      graph.add(implNode, VALUE_CACHE_SIZE, vf.createLiteral(valueCacheSize));
    }
    if (valueIDCacheSize >= 0) {
      graph.add(implNode, VALUE_ID_CACHE_SIZE, vf.createLiteral(valueIDCacheSize));
    }
    if (namespaceCacheSize >= 0) {
      graph.add(implNode, NAMESPACE_CACHE_SIZE, vf.createLiteral(namespaceCacheSize));
    }
    if (namespaceIDCacheSize >= 0) {
      graph.add(implNode, NAMESPACE_ID_CACHE_SIZE, vf.createLiteral(namespaceIDCacheSize));
    }

    return implNode;
  }
View Full Code Here

    // fetch the Repository, a Connection and a ValueFactory
    Repository repository = (Repository) model
        .getUnderlyingModelImplementation();
    RepositoryConnection connection = repository.getConnection();
    ValueFactory factory = repository.getValueFactory();

    // add a statement
    model.addStatement(subject, predicate, object);

    // convert the statement parts to OpenRDF data types
View Full Code Here

            lon = Float.parseFloat(coords[1]);
        } catch (NumberFormatException nfe) {
            return;
        }

        final ValueFactory factory = new Any23ValueFactoryWrapper(ValueFactoryImpl.getInstance(), out);
        BNode point = factory.createBNode();
        out.writeTriple(extractionContext.getDocumentURI(), expand("dcterms:related"), point);
        out.writeTriple(point, expand("rdf:type"), expand("geo:Point"));
        out.writeTriple(point, expand("geo:lat"), factory.createLiteral(Float.toString(lat)));
        out.writeTriple(point, expand("geo:long"), factory.createLiteral(Float.toString(lon)));
    }
View Full Code Here

    @Test
    public void testLinkExtraction() throws RepositoryException {
        assertExtract("html/html-head-link-extractor.html");
        assertModelNotEmpty();
        final ValueFactory valueFactory = new ValueFactoryImpl();
        final URI externalLinkURI = valueFactory.createURI("http://www.myexperiment.org/workflows/16.rdf");
        assertContains(
                AbstractExtractorTestCase.baseURI,
                valueFactory.createURI("http://www.w3.org/1999/xhtml/vocab#alternate"),
                externalLinkURI

        );
        assertContains(
                externalLinkURI,
                valueFactory.createURI("http://purl.org/dc/terms/title"),
                valueFactory.createLiteral("RDF+XML")

        );
        assertContains(
                externalLinkURI,
                valueFactory.createURI("http://purl.org/dc/terms/format"),
                valueFactory.createLiteral("application/rdf+xml")

        );
    }
View Full Code Here

            ExtractionContext extractionContext,
            Document in,
            ExtractionResult out
    ) throws IOException, ExtractionException {
        HTMLDocument html = new HTMLDocument(in);
        ValueFactory vf = ValueFactoryImpl.getInstance();

        final List<Node> headLinkNodes = DomUtils.findAll(
                in,
                "/HTML/HEAD/LINK[(" +
                        "@type='application/rdf+xml' or " +
                        "@type='text/rdf' or " +
                        "@type='application/x-turtle' or " +
                        "@type='application/turtle' or " +
                        "@type='text/turtle' or " +
                        "@type='text/rdf+n3'" +
                        ") and @href and @rel]"
        );
        for (Node node : headLinkNodes) {
            final URI href = html.resolveURI(DomUtils.find(node, "@href"));
            final String rel = DomUtils.find(node, "@rel");
            out.writeTriple(
                    extractionContext.getDocumentURI(),
                    vf.createURI(XHTML.NS + rel),
                    href
            );
            final String title = DomUtils.find(node, "@title");
            if (title != null && !"".equals(title)) {
                out.writeTriple(
                        href,
                        factory.getPrefixes().expand("dcterms:title"),
                        vf.createLiteral(title)
                );
            }
            final String type = DomUtils.find(node, "@type");
            if (type != null && !"".equals(type)) {
                out.writeTriple(
                        href,
                        factory.getPrefixes().expand("dcterms:format"),
                        vf.createLiteral(type)
                );
            }
        }
    }
View Full Code Here

    private void checkTriple(String predicate, VerificationMode verificationMode)
    throws TripleHandlerException {
        final String DOCUMENT_URI = "http://an.html.page";
        final TripleHandler mockTripleHandler = mock(TripleHandler.class);
        final ValueFactory valueFactory = new ValueFactoryImpl();
        ExtractionContext extractionContext = new ExtractionContext(
                "test-extractor",
                valueFactory.createURI(DOCUMENT_URI)
        );
        final IgnoreAccidentalRDFa ignoreAccidentalRDFa = new IgnoreAccidentalRDFa(mockTripleHandler, true);
        ignoreAccidentalRDFa.openContext(extractionContext);
        ignoreAccidentalRDFa.receiveTriple(
                valueFactory.createURI(DOCUMENT_URI),
                valueFactory.createURI(predicate),
                valueFactory.createURI("http://www.myedu.com/modules/20110519065453/profile.css"),
                valueFactory.createURI(DOCUMENT_URI),
                extractionContext
        );
        ignoreAccidentalRDFa.close();

        verify(
View Full Code Here

      }
     
      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: FSL path must end on node";
        throw new ParserConfigurationException(error);
      }
      }
    }
  }
  else if (renderLens.getBasicInstanceDomains() != null)
  {
    java.lang.String[] bid = renderLens.getBasicInstanceDomains();
    SesameLens sl = (SesameLens)renderLens;
    HashMap resSet = new HashMap();

    for (int j = 0; j < bid.length; j++)
    {
      ValueFactory f = dataRepo.getValueFactory();
      URI r = f.createURI(bid[j]);
      if (r == null)
        continue;

      // Don't render resource twice (???)
      if (resSet.containsKey(r))
          continue;
      resSet.put(r, null);
     
      Element eR = createResourceElement(fd, dataRepo, doc, sl, null, r, Constants.DEFAULT_MAX_DEPTH);
      parent.appendChild(eR);
    }
  }
  else if (renderLens.getBasicClassDomains() != null)
  {
    java.lang.String[] cd = renderLens.getBasicClassDomains();
    SesameLens sl = (SesameLens)renderLens;
    ValueFactory f = dataRepo.getValueFactory();
    URI pRDFType = f.createURI(Constants.RDF_NAMESPACE_URI + "type")
    HashMap resSet = new HashMap();

    for (int j = 0; j < cd.length; j++)
    {
      try {
        RepositoryConnection connection = dataRepo.getConnection();
        RepositoryResult<Statement> si = connection.getStatements(null, RDF.TYPE, f.createURI(cd[j]), true);
        Statement s;
        Resource r;
        while (si.hasNext()){
          s = si.next();
          r = s.getSubject();
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;
              //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);
        }
        else if (end instanceof Statement)
        {
          String error = "Render Error: FSL path must end on node";
          throw new ParserConfigurationException(error);
        }
        }
      }
    }
    // I don't know if here it should be return metadata here !!!
    else if (renderLens.getBasicInstanceDomains() != null)
    {
      System.out.println("Rendering getBasicInstanceDomains()...");
      java.lang.String[] bid = renderLens.getBasicInstanceDomains();
      SesameLens sl = (SesameLens)renderLens;
      HashMap resSet = new HashMap();

      for (int j = 0; j < bid.length; j++)
      {
       
        ValueFactory f = dataRepo.getValueFactory();
        URI r = f.createURI(bid[j]);
        if (r == null)
          continue;

        // Don't render resource twice (???)
        if (resSet.containsKey(r))
View Full Code Here

TOP

Related Classes of org.openrdf.model.ValueFactory

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.