Changeset 40:03e0f7574224 in AnnotationManagerN4J


Ignore:
Timestamp:
Sep 26, 2012, 12:56:42 PM (12 years ago)
Author:
casties
Branch:
default
Message:

saving and loading resource targets should work now (no searching yet)

Location:
src/main/java/de/mpiwg/itgroup/annotations
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/Annotation.java

    r20 r40  
    3939   
    4040    /**
    41      * The types of annotation targets.
     41     * The types of annotation target fragments.
    4242     *
    4343     */
     
    5050     */
    5151    protected FragmentTypes fragmentType;
     52   
     53   
     54    /**
     55     * The uri of the resource that is annotated e.g. a book.
     56     * The target is part of this resource e.g. a page of a book.
     57     */
     58    protected String resourceUri;
    5259   
    5360    /**
     
    224231
    225232    /**
     233     * @return the resourceUri
     234     */
     235    public String getResourceUri() {
     236        return resourceUri;
     237    }
     238
     239    /**
     240     * @param resourceUri the resourceUri to set
     241     */
     242    public void setResourceUri(String resourceUri) {
     243        this.resourceUri = resourceUri;
     244    }
     245
     246    /**
    226247     * @return the creator
    227248     */
  • src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java

    r36 r40  
    528528             */
    529529            String targetBaseUri = annot.getTargetBaseUri();
     530            Node targetNode = null;
    530531            if (targetBaseUri != null) {
    531                 Node target = getOrCreateTargetNode(targetBaseUri);
    532                 getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, target);
     532                targetNode = getOrCreateTargetNode(targetBaseUri, NodeTypes.TARGET);
     533                getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, targetNode);
    533534            }
    534535
     
    541542                annotNode.setProperty("targetFragment", targetFragment);
    542543                annotNode.setProperty("fragmentType", fragmentType.name());
     544            }
     545
     546            /*
     547             * the annotation resource
     548             */
     549            String resourceUri = annot.getResourceUri();
     550            if (resourceUri != null) {
     551                Node resource = getOrCreateTargetNode(resourceUri, NodeTypes.RESOURCE);
     552                getOrCreateRelation(annotNode, RelationTypes.ANNOTATES, resource);
     553                getOrCreateRelation(targetNode, RelationTypes.PART_OF, resource);
    543554            }
    544555
     
    712723     */
    713724    protected Relationship getOrCreateRelation(Node start, RelationshipType type, Node end) {
     725        if (start == null || end == null) return null;
    714726        if (start.hasRelationship()) {
    715727            // there are relations
     
    754766    }
    755767
    756     protected Node getOrCreateTargetNode(String uri) {
    757         Index<Node> idx = getNodeIndex(NodeTypes.TARGET);
     768    protected Node getOrCreateTargetNode(String uri, NodeTypes type) {
     769        Index<Node> idx = getNodeIndex(type);
    758770        IndexHits<Node> targets = idx.get("uri", uri);
    759771        Node target = targets.getSingle();
     
    763775            try {
    764776                target = graphDb.createNode();
    765                 target.setProperty("TYPE", NodeTypes.TARGET.name());
     777                target.setProperty("TYPE", type.name());
    766778                target.setProperty("uri", uri);
    767779                idx.add(target, "uri", uri);
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java

    r34 r40  
    2424import de.mpiwg.itgroup.annotations.Annotation;
    2525import de.mpiwg.itgroup.annotations.Person;
    26 import de.mpiwg.itgroup.annotations.Tag;
    2726import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
    2827import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java

    r22 r40  
    188188            jo.put("text", annot.getBodyText());
    189189            jo.put("uri", annot.getTargetBaseUri());
     190            if (annot.getResourceUri() != null) {
     191                jo.put("resource", annot.getResourceUri());
     192            }
    190193
    191194            /*
     
    442445        }
    443446        /*
     447         * resource uri
     448         */
     449        if (jo.has("resource")) {
     450            annot.setResourceUri(jo.getString("resource"));
     451        }
     452        /*
    444453         * annotation text
    445454         */
Note: See TracChangeset for help on using the changeset viewer.