Exemple #1
0
  @Test
  public void shouldSortTriplesForDisplay() {
    final Model model = createDefaultModel();

    model.setNsPrefix("prefix", "namespace");
    final Property propertyA = model.createProperty("namespace", "a");
    final Property propertyB = model.createProperty("namespace", "b");
    final Property propertyC = model.createProperty("c");
    final Literal literalA = model.createLiteral("a");
    final Literal literalB = model.createLiteral("b");
    final Resource resourceB = model.createResource("b");
    model.add(resourceB, propertyA, literalA);

    final Resource a = model.createResource("a");
    model.add(a, propertyC, literalA);

    model.add(a, propertyB, literalA);

    model.add(a, propertyA, literalA);
    model.add(a, propertyA, literalB);

    final Iterator<Quad> iterator = DatasetFactory.create(model).asDatasetGraph().find();

    final List<Quad> sortedTriples = testObj.getSortedTriples(model, iterator);

    sortedTriples.get(0).matches(ANY, a.asNode(), propertyA.asNode(), literalA.asNode());
    sortedTriples.get(1).matches(ANY, a.asNode(), propertyA.asNode(), literalB.asNode());
    sortedTriples.get(2).matches(ANY, a.asNode(), propertyB.asNode(), literalA.asNode());
    sortedTriples.get(3).matches(ANY, a.asNode(), propertyC.asNode(), literalA.asNode());
    sortedTriples.get(4).matches(ANY, resourceB.asNode(), propertyC.asNode(), literalA.asNode());
  }
Exemple #2
0
  public static String RenderTemplatePage(Bindings b, String templateName) throws IOException {

    MediaType mt = MediaType.TEXT_HTML;
    Resource config = model.createResource("eh:/root");
    Mode prefixMode = Mode.PreferPrefixes;
    ShortnameService sns = new StandardShortnameService();

    List<Resource> noResults = CollectionUtils.list(root.inModel(model));
    Graph resultGraph = graphModel.getGraph();

    resultGraph.getPrefixMapping().setNsPrefix("api", API.NS);
    resultGraph.add(Triple.create(root.asNode(), API.items.asNode(), RDF.nil.asNode()));

    APIResultSet rs = new APIResultSet(resultGraph, noResults, true, true, "details", View.ALL);
    VelocityRenderer vr = new VelocityRenderer(mt, null, config, prefixMode, sns);

    VelocityRendering vx = new VelocityRendering(b, rs, vr);

    VelocityEngine ve = vx.createVelocityEngine();
    VelocityContext vc = vx.createVelocityContext(b);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Writer w = new OutputStreamWriter(bos, "UTF-8");
    Template t = ve.getTemplate(templateName);

    t.merge(vc, w);
    w.close();

    return bos.toString();
  }
 private void createProblemQuad(String resource, Resource problem) {
   Quad q =
       new Quad(
           null,
           ModelFactory.createDefaultModel().createResource(resource).asNode(),
           QPRO.exceptionDescription.asNode(),
           problem.asNode());
   this._problemList.add(q);
 }
  private RDFResourceTree createTree(Resource resource, Model model, int maxDepth) {
    nodeId = 0;
    Map<Resource, SortedSet<Statement>> resource2Statements =
        new HashMap<Resource, SortedSet<Statement>>();

    fillMap(resource, model, resource2Statements);

    RDFResourceTree tree = new RDFResourceTree(resource.asNode());
    fillTree(resource, tree, resource2Statements, 0, maxDepth);

    return tree;
  }
  protected boolean populateKeyValue(Text key, Triple value) {

    Resource subject;
    Property predicate = null;
    RDFNode object;

    inErr = false;

    skipWhiteSpace();
    if (in.eof()) {
      return false;
    }

    subject = readResource();
    if (inErr) return false;

    skipWhiteSpace();
    try {
      predicate = model.createProperty(readResource().getURI());
    } catch (Exception e1) {
      e1.printStackTrace();
      errorHandler.fatalError(e1);
    }
    if (inErr) return false;

    skipWhiteSpace();
    object = readNode();
    if (inErr) return false;

    skipWhiteSpace();
    if (badEOF()) return false;

    if (!expect(".")) return false;

    try {
      key.set(getCurrentFileName());
      value.setTriple(subject.asNode(), predicate.asNode(), object.asNode());
      recordCounter++;
      // System.out.println("Triple value:"+value);
      return true;
    } catch (Exception e2) {
      e2.printStackTrace();
      errorHandler.fatalError(e2);
    }

    return false;
  }
  @Override
  public void compute(Quad quad) {
    logger.debug("Computing : {} ", quad.asTriple().toString());

    Node subject = quad.getSubject();
    Node object = quad.getObject();

    if (quad.getObject().equals(FOAF.Document.asNode())) {
      docs.putIfAbsent(subject.toString(), new DigitalSignature());
    }

    if (quad.getPredicate().equals(ASSURANCE.asNode())) {
      DigitalSignature ds;
      if (endorsements.containsKey(object.getURI())) {
        ds = endorsements.get(object.getURI());
      } else {
        ds = new DigitalSignature();
        ds.endorcement = object.getURI();
      }

      ds.assurance = subject.getURI();

      docs.put(subject.toString(), ds);
      endorsements.put(object.getURI(), ds);
    }

    if (quad.getPredicate().equals(ENDORSER.asNode())) {
      DigitalSignature ds;
      if (endorsements.containsKey(object.getURI())) {
        ds = endorsements.get(object.getURI());
      } else {
        ds = new DigitalSignature();
        ds.endorcement = subject.getURI();
      }

      ds.endorcer = object.getURI();
    }

    if (quad.getObject().equals(ENDORSEMENT.asNode())) {
      DigitalSignature ds = new DigitalSignature();
      ds.endorcement = subject.getURI();

      endorsements.putIfAbsent(subject.getURI(), ds);
    }
  }
Exemple #7
0
  /**
   * Get an {@link RdfStream} for the given JCR NodeIterator
   *
   * @param nodeIterator
   * @param iteratorSubject
   * @return
   * @throws RepositoryException
   */
  public RdfStream getJcrPropertiesModel(
      final Iterator<Node> nodeIterator, final Resource iteratorSubject)
      throws RepositoryException {

    final RdfStream results = new RdfStream();
    while (nodeIterator.hasNext()) {
      final Node node = nodeIterator.next();
      results.concat(new PropertiesRdfContext(node, graphSubjects, llstore));
      if (iteratorSubject != null) {
        results.concat(
            singleton(
                create(
                    iteratorSubject.asNode(),
                    HAS_MEMBER_OF_RESULT.asNode(),
                    graphSubjects.getSubject(node.getPath()).asNode())));
      }
    }
    return results;
  }
 /**
  * Creates a resource from this SPDX Checksum
  *
  * @param model
  * @return
  */
 public Resource createResource(Model model) {
   this.model = model;
   Resource type =
       model.createResource(
           SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_CHECKSUM);
   Resource r = model.createResource(type);
   if (algorithm != null) {
     Property algProperty =
         model.createProperty(
             SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_ALGORITHM);
     Resource algResource = model.createResource(ALGORITHM_TO_URI.get(algorithm));
     r.addProperty(algProperty, algResource);
   }
   if (this.value != null) {
     Property valueProperty =
         model.createProperty(
             SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_CHECKSUM_VALUE);
     r.addProperty(valueProperty, this.value);
   }
   this.checksumNode = r.asNode();
   this.checksumResource = r;
   return r;
 }
 /** @see com.hp.hpl.jena.rdf.model.RDFNode#asNode() */
 public Node asNode() {
   // TODO is graph level sync needed?
   // logger.warn("Synchronization not implemented");
   return wrapped.asNode();
 }