From: <dfl...@us...> - 2013-12-10 09:56:58
|
Revision: 4201 http://sourceforge.net/p/dl-learner/code/4201 Author: dfleischhacker Date: 2013-12-10 09:56:55 +0000 (Tue, 10 Dec 2013) Log Message: ----------- Retrieve entities from all possible leaf nodes in the TokenTree Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/TokenTree.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/TokenTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/TokenTree.java 2013-12-09 15:38:09 UTC (rev 4200) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/TokenTree.java 2013-12-10 09:56:55 UTC (rev 4201) @@ -81,7 +81,7 @@ public Set<Entity> get(List<Token> tokens) { TokenTree curNode = this; for (Token t : tokens) { - TokenTree nextNode = curNode.children.get(t); + TokenTree nextNode = getNextTokenTree(curNode, t); if (nextNode == null) { return null; } @@ -90,6 +90,25 @@ return curNode.entities; } + public Set<Entity> getAllEntities(List<Token> tokens) { + HashSet<Entity> resEntities = new HashSet<>(); + getAllEntitiesRec(tokens, 0, this, resEntities); + return resEntities; + } + + public void getAllEntitiesRec(List<Token> tokens, int curPosition, TokenTree curTree, HashSet<Entity> resEntities) { + if (curPosition == tokens.size()) { + resEntities.addAll(curTree.entities); + return; + } + Token t = tokens.get(curPosition); + for (Map.Entry<Token, TokenTree> entry : curTree.children.entrySet()) { + if (t.equalsWithAlternativeForms(entry.getKey())) { + getAllEntitiesRec(tokens, curPosition + 1, entry.getValue(), resEntities); + } + } + } + /** * Returns the list of tokens which are the longest match with entities assigned in this tree. * @@ -148,7 +167,7 @@ } /** - * Returns the original token for the longest match + * Returns the original ontology tokens for the longest match */ public List<Token> getOriginalTokensForLongestMatch(List<Token> tokens) { TokenTree fallback = this.entities.isEmpty() ? null : this; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |