Created
May 13, 2013 09:48
-
-
Save timeu/5567247 to your computer and use it in GitHub Desktop.
Spring Data Neo4j configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<neo4j:config graphDatabaseService="graphDatabaseService"/> | |
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase"> | |
<constructor-arg index="0" value="${neo4j.host}" /> | |
</bean> | |
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory"> | |
<constructor-arg index="0" ref="graphDatabaseService"/> | |
<constructor-arg index="1" value="Noop"/> | |
</bean> | |
<neo4j:repositories base-package="com.xxx.domain" /> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NodeEntity | |
public class Term extends BaseGraphOntologyEntity{ | |
@Indexed(unique=true) | |
private String id; | |
private String name; | |
private String definition; | |
private String synonyms; | |
@RelatedToVia(type="is_a",direction=Direction.INCOMING) | |
private Set<IsATerm> is_a_children; | |
@RelatedToVia(type="is_a",direction=Direction.OUTGOING) | |
Set<IsATerm> is_a_parents; | |
@RelatedToVia(type="part_of",direction = Direction.INCOMING) | |
Set<PartOfTerm> part_of_children; | |
@RelatedToVia(type="part_of",direction = Direction.OUTGOING) | |
Set<PartOfTerm> part_of_parents; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface TermRepository extends GraphRepository<Term> { | |
public Term findById(String id); | |
@Query("START n=node:Term(id={0}),m =node:Term(id={1}) match p = shortestPath(n-[*]->m) RETURN p") | |
public EndResult<EntityPath<Term,Term>> findShortestPath(String start,String end); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testFindShortestPath() { | |
EndResult<EntityPath<Term,Term>> endResult = repository.findShortestPath("TO:0000166","TO:0000387"); | |
EntityPath<Term,Term> path = endResult.single(); | |
List<Long> idsInPath = Lists.newArrayList(); | |
for (Node node : path.nodes()) { | |
idsInPath.add(node.getId()); | |
} | |
long[] checkIds = {909,784,1096,13,907,174}; | |
assertEquals(6,idsInPath.size()); | |
assertArrayEquals(checkIds, Longs.toArray(idsInPath)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment