Package org.apache.clerezza.rdf.utils

Examples of org.apache.clerezza.rdf.utils.GraphNode$Acceptor


    Lock lock = existingNode.writeLock();
    try {
      lock.lock();
      for (FeatureStructure uimaObject : uimaObjects) {
        // create a new node for the current Annotation
        GraphNode annotationNode = new GraphNode(new UriRef(new StringBuilder(ENTITY.Annotation.getUnicodeString()).
                append(uimaObject.hashCode()).toString()), existingNode.getGraph());
        log.info(new StringBuilder("Node created for Type ").append(uimaObject.getType().toString()).toString());

        // set Annotation specific properties for the node
        if (uimaObject instanceof Annotation) {
          Annotation annotation = (Annotation) uimaObject;
          String coveredText = annotation.getCoveredText();
          annotationNode.addPropertyValue(ENTITY.coveredText, coveredText);
          log.info(new StringBuilder("Node wraps Annotation with coveredText:").append(coveredText).toString());
        }

        //XXX : in OpenCalais the type is an URI so it maybe reasonable to put another node here
        annotationNode.addPropertyValue(ENTITY.uimaType, uimaObject.getType().getName());

        /* inspect features of the annotation */
        Type type = uimaObject.getType();
        for (Feature feature : type.getFeatures()) {

          // create a new feature node
          GraphNode featureNode = new GraphNode(new UriRef(new StringBuilder(ENTITY.Feature.getUnicodeString()).
                  append(feature.hashCode() / uimaObject.hashCode()).toString()), annotationNode.getGraph());
          log.info(new StringBuilder("Node created for Feature ").append(feature.getName()).toString());

          // set feature name and value if not null
          featureNode.addPropertyValue(ENTITY.featureName, feature.getName());

          String featureValue = null;
          try {
            featureValue = uimaObject.getFeatureValueAsString(feature);
          } catch (CASRuntimeException sofaEx) {
            try {
              // this is usually due to Sofa having a range of {2}
              featureValue = uimaObject.getFeatureValue(feature).toString();
            } catch (Exception ex) {
              // do nothing at the moment
              log.warn(new StringBuilder("Unable to create feature value - ").append(ex.toString()).append(" (").
                      append(sofaEx.toString()).append(")").toString());
            }
          }

          if (featureValue != null) {
            featureNode.addPropertyValue(ENTITY.featureValue, featureValue);
            log.info(new StringBuilder("Added feature ").append(feature.getName()).append(" with value ")
                    .append(featureValue.toString()).toString());
          }

          // add feature to the annotation node
          annotationNode.addProperty(ENTITY.hasFeature, featureNode.getNode());
        }

        // finally add the triple to the existing node
        existingNode.addProperty(ENTITY.contains, annotationNode.getNode());

View Full Code Here


  private void testWithFiles(String triples, String template, String expected)
      throws Exception {
    TripleCollection tc = Parser.getInstance().parse(
        getClass().getResourceAsStream(triples),
        "text/turtle");
    GraphNode res = new GraphNode(root, tc);
    ByteArrayOutputStream baosRendered = new ByteArrayOutputStream();
    renderlet.render(res, null, null, null,
        getClass().getResource(template).toURI(),
        null, null, null, baosRendered);
    ByteArrayOutputStream baosExpected = new ByteArrayOutputStream();
View Full Code Here

    public Object getDescription(@Context UriInfo uriInfo){
      String absoluteUriPath = uriInfo.getAbsolutePath().toString();
      MGraph contentMGraph = tcManager.getMGraph(Constants.CONTENT_GRAPH_URI);
        UriRef uri = new UriRef(absoluteUriPath.substring(0,
            absoluteUriPath.length() - DESCRIPTION_SUFFIX.length()));
        GraphNode graphNode = new GraphNode(uri, contentMGraph);
        return graphNode.getNodeContext();
    }
View Full Code Here

    });
    final Iterator<Resource> entriesIter = titledContent.getObjects(DISCOBITS.contains);
    while (entriesIter.hasNext()) {
      Resource resource = entriesIter.next();
      entries.add(new GraphNode((NonLiteral) resource,titledContent.getGraph()));
    }
    final List<GraphNode> result = new ArrayList<GraphNode>();
    for (GraphNode graphNode : entries) {
      Iterator<Resource> holded = graphNode.getObjects(DISCOBITS.holds);
      if (!holded.hasNext()) {
        throw new RuntimeException(
            "Titled Content must contain a first element: "+graphNode.getNodeContext());
      }
      result.add(new GraphNode(holded.next(),
          titledContent.getGraph()));
    }
    return result;
  }
View Full Code Here

  private class RenderFunction implements RenderingFunction<Object, String> {

    @Override
    public String process(Object... values) throws IOException {
      NonLiteral resource = (NonLiteral) values[0];
      GraphNode graphNode = new GraphNode(resource, graph);
      String mode = null;
      if (values.length > 1) {
        mode = (String) values[1];
      }
      ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

   */
  @GET
  @Produces({"*/*"})
  public Object getResource(@Context UriInfo uriInfo) {
    final UriRef uri = new UriRef(uriInfo.getAbsolutePath().toString());
      final GraphNode graphNode = getResourceAsGraphNode(uriInfo);
    if (graphNode == null) {
      return resourceUnavailable(uri, uriInfo);
    }
    InfoDiscobit infoDiscobit = InfoDiscobit.createInstance(graphNode);
    if (infoDiscobit != null) {
View Full Code Here

    }
  }

  private GraphNode getResourceAsGraphNode(UriInfo uriInfo) {
    final UriRef uri = new UriRef(uriInfo.getAbsolutePath().toString());
    GraphNode result = graphNodeProvider.getLocal(uri);
    //could chck if nodeContext > 0, but this would be less efficient
    TripleCollection tc = result.getGraph();
    if (tc.filter(uri, null, null).hasNext()) {
      return result;
    }
    if (tc.filter(null, null, uri).hasNext()) {
      return result;
View Full Code Here

      String depthHeader = WebDavUtils.getHeaderAsString(headers, "Depth");
      if (depthHeader == null) {
        depthHeader = WebDavUtils.infinite;
      }
      final MGraph mGraph = cgProvider.getContentGraph();
      GraphNode node = new GraphNode(nodeUri, mGraph);
      if (body != null) {
        Document requestDoc = WebDavUtils.sourceToDocument(body);
        Node propfindNode = WebDavUtils.getNode(requestDoc, WebDavUtils.propfind);
        Node requestNode = WebDavUtils.getFirstChild(propfindNode);
        String requestType = requestNode.getLocalName();
View Full Code Here

      return resourceUnavailable(nodeUri, uriInfo);
    }
    try {
      Document requestDoc = WebDavUtils.sourceToDocument(body);
      final MGraph mGraph = cgProvider.getContentGraph();
      GraphNode node = new GraphNode(nodeUri, mGraph);
      NodeList propsToSet = null;
      NodeList propsToRemove = null;
      Node proppatchNode = WebDavUtils.getNode(requestDoc, WebDavUtils.proppatch);
      NodeList childNodes = proppatchNode.getChildNodes();
      for (int i = 0; i < childNodes.getLength(); i++) {
View Full Code Here

   */
  @MOVE
  public Response move(@Context UriInfo uriInfo, @Context HttpHeaders headers) {
    UriRef nodeUri = new UriRef(uriInfo.getAbsolutePath().toString());
    final LockableMGraph mGraph = cgProvider.getContentGraph();
    GraphNode node = new GraphNode(nodeUri, mGraph);
    String targetString = WebDavUtils.getHeaderAsString(headers,
          "Destination");
    UriRef targetUri = new UriRef(targetString);
    String overwriteHeader = WebDavUtils.getHeaderAsString(headers, "Overwrite");
    boolean overwriteTarget = "T".equalsIgnoreCase(overwriteHeader);
    if (nodeAtUriExists(targetUri)) {
      if (overwriteTarget) {
        new GraphNode(targetUri, mGraph).deleteNodeContext();
      } else {
        return Response.status(Status.PRECONDITION_FAILED).build();
      }
    }
    Lock l = mGraph.getLock().writeLock();
    l.lock();
    try {
      Iterator<Triple> oldParentTripleIter
          = mGraph.filter(nodeUri, HIERARCHY.parent, null);
      if (oldParentTripleIter.hasNext()) {
        oldParentTripleIter.next();
        oldParentTripleIter.remove();
      }
      while (oldParentTripleIter.hasNext()) {
        logger.error("more than one parent statement: "+oldParentTripleIter.next());
        oldParentTripleIter.remove();
      }
      Lock writeLock = node.writeLock();
      writeLock.lock();
      try {
        node.replaceWith(targetUri);
      } finally {
        writeLock.unlock();
      }
      new CollectionCreator(mGraph).createContainingCollections(targetUri);
      try {
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.utils.GraphNode$Acceptor

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.