Changeset 42:aa2bb7ac04d9 in AnnotationManagerN4J for src
- Timestamp:
- Sep 26, 2012, 2:12:46 PM (13 years ago)
- Branch:
- default
- Location:
- src/main/java/de/mpiwg/itgroup/annotations
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java
r40 r42 26 26 import de.mpiwg.itgroup.annotations.Group; 27 27 import de.mpiwg.itgroup.annotations.Person; 28 import de.mpiwg.itgroup.annotations.Resource; 28 29 import de.mpiwg.itgroup.annotations.Tag; 30 import de.mpiwg.itgroup.annotations.Target; 31 import de.mpiwg.itgroup.annotations.Uri; 29 32 30 33 /** … … 92 95 } 93 96 94 public List<Actor> getActors(String key, String query, NodeTypes type) { 95 ArrayList<Actor> actors = new ArrayList<Actor>(); 97 /** 98 * Returns the Node with the given key and value. 99 * Key has to be indexed. 100 * 101 * @param key 102 * @param value 103 * @param type 104 * @return 105 */ 106 public Node getNodeFromIndex(String key, String value, NodeTypes type) { 107 if (key == null || value == null) return null; 108 Node person = getNodeIndex(type).get(key, value).getSingle(); 109 return person; 110 } 111 112 /** 113 * Returns list of Actors of given type (Group or Person). 114 * Key has to be indexed. 115 * 116 * @param key 117 * @param query 118 * @param type 119 * @return 120 */ 121 @SuppressWarnings("unchecked") 122 public <T extends Actor> List<T> getActors(String key, String query, NodeTypes type) { 123 ArrayList<T> actors = new ArrayList<T>(); 96 124 Index<Node> idx = getNodeIndex(type); 97 125 if (key == null) { … … 102 130 for (Node actorNode : actorNodes) { 103 131 Actor actor = createActorFromNode(actorNode); 104 actors.add( actor);132 actors.add((T) actor); 105 133 } 106 134 return actors; 107 135 } 108 109 /** 110 * Returns List of Groups. 111 * Key has to be indexed. 112 * 136 137 /** 138 * Returns list of groups. Key has to be indexed. 113 139 * @param key 114 140 * @param query … … 116 142 */ 117 143 public List<Group> getGroups(String key, String query) { 118 ArrayList<Group> groups = new ArrayList<Group>(); 119 Index<Node> idx = getNodeIndex(NodeTypes.GROUP); 144 List<Group> groups = getActors(key, query, NodeTypes.GROUP); 145 return groups; 146 } 147 148 /** 149 * Returns list of Persons. Key has to be indexed. 150 * @param key 151 * @param query 152 * @return 153 */ 154 public List<Person> getPersons(String key, String query) { 155 List<Person> persons = getActors(key, query, NodeTypes.PERSON); 156 return persons; 157 } 158 159 /** 160 * Returns list of uri-like objects of given type (Target or Resource). 161 * Key has to be indexed. 162 * 163 * @param key 164 * @param query 165 * @param type 166 * @return 167 */ 168 @SuppressWarnings("unchecked") 169 public <T extends Uri> List<T> getUris(String key, String query, NodeTypes type) { 170 ArrayList<T> uris = new ArrayList<T>(); 171 Index<Node> idx = getNodeIndex(type); 120 172 if (key == null) { 121 173 key = "uri"; 122 174 query = "*"; 123 175 } 124 IndexHits<Node> groupNodes = idx.query(key, query); 125 for (Node groupNode : groupNodes) { 126 Actor group = createActorFromNode(groupNode); 127 groups.add((Group) group); 128 } 129 return groups; 130 } 131 176 IndexHits<Node> actorNodes = idx.query(key, query); 177 for (Node actorNode : actorNodes) { 178 Uri uri = createUriFromNode(actorNode); 179 uris.add((T) uri); 180 } 181 return uris; 182 } 183 184 185 /** 186 * Returns list of Targets. Key has to be indexed. 187 * @param key 188 * @param query 189 * @return 190 */ 191 public List<Target> getTargets(String key, String query) { 192 List<Target> targets = getUris(key, query, NodeTypes.TARGET); 193 return targets; 194 } 195 196 /** 197 * Returns list of Resources. Key has to be indexed. 198 * @param key 199 * @param query 200 * @return 201 */ 202 public List<Resource> getResources(String key, String query) { 203 List<Resource> targets = getUris(key, query, NodeTypes.RESOURCE); 204 return targets; 205 } 206 132 207 /** 133 208 * Returns List of Annotations. … … 490 565 return new Tag(id, uri, name); 491 566 567 } 568 569 protected Uri createUriFromNode(Node uriNode) { 570 if (uriNode == null) return null; 571 String uri = (String) uriNode.getProperty("uri", null); 572 String type = (String) uriNode.getProperty("TYPE", null); 573 if (type != null && type.equals("TARGET")) { 574 return new Target(uri); 575 } else if (type != null && type.equals("RESOURCE")) { 576 return new Resource(uri); 577 } 578 return null; 492 579 } 493 580 … … 981 1068 } 982 1069 1070 public List<Annotation> getAnnotationsByResource(String resourceUri) { 1071 ArrayList<Annotation> ret = new ArrayList<Annotation>(); 1072 Node tag = getNodeFromIndex("uri", resourceUri, NodeTypes.RESOURCE); 1073 Iterable<Relationship> rels = tag.getRelationships(Direction.INCOMING, RelationTypes.ANNOTATES); 1074 for (Relationship rel : rels) { 1075 Node node = rel.getStartNode(); 1076 ret.add(createAnnotationFromNode(node)); 1077 } 1078 return ret; 1079 } 1080 983 1081 }
Note: See TracChangeset
for help on using the changeset viewer.