diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-10 18:17:06 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-11 12:34:47 +0100 |
| commit | 17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch) | |
| tree | 47e9310a0cff869d9ec017dcb2c81876407782c8 /src/uk/ac/ox/cs/pagoda/model/Trie.java | |
| parent | 8651164cd632a5db310b457ce32d4fbc97bdc41c (diff) | |
| download | ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.tar.gz ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.zip | |
[pagoda] Move project to Scala
This commit includes a few changes:
- The repository still uses Maven to manage dependency but it is now a
Scala project.
- The code has been ported from OWLAPI 3.4.10 to 5.1.20
- A proof of concept program using both RSAComb and PAGOdA has been
added.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/model/Trie.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/model/Trie.java | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/model/Trie.java b/src/uk/ac/ox/cs/pagoda/model/Trie.java deleted file mode 100644 index eb9e71b..0000000 --- a/src/uk/ac/ox/cs/pagoda/model/Trie.java +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.model; | ||
| 2 | |||
| 3 | public class Trie { | ||
| 4 | |||
| 5 | private TrieNode root = new TrieNode(""); | ||
| 6 | private Status findStatus; | ||
| 7 | |||
| 8 | public void insert(String key, AnswerTerm term) { | ||
| 9 | findStatus.lastNode.insert(key, findStatus.lastIndex, term); | ||
| 10 | } | ||
| 11 | |||
| 12 | public AnswerTerm find(String key) { | ||
| 13 | findStatus = root.find(key, 0); | ||
| 14 | return findStatus.term; | ||
| 15 | } | ||
| 16 | |||
| 17 | } | ||
| 18 | |||
| 19 | class TrieNode { | ||
| 20 | |||
| 21 | String relative; | ||
| 22 | TrieNode[] children = new TrieNode[256]; | ||
| 23 | |||
| 24 | public TrieNode(String s) { | ||
| 25 | relative = s; | ||
| 26 | } | ||
| 27 | |||
| 28 | public void insert(String key, int index, AnswerTerm term) { | ||
| 29 | int nextChar = (int) key.charAt(index); | ||
| 30 | if (children[nextChar] == null) { | ||
| 31 | children[nextChar] = new TrieLeaf(key.substring(index), term); | ||
| 32 | } | ||
| 33 | else { | ||
| 34 | TrieNode next = children[nextChar]; | ||
| 35 | int len = next.isPrefixOf(key, index); | ||
| 36 | if (len == next.relative.length()) | ||
| 37 | insert(key, index + len, term); | ||
| 38 | else { | ||
| 39 | TrieNode newNext = new TrieNode(next.relative.substring(0, len)); | ||
| 40 | next.relative = next.relative.substring(len); | ||
| 41 | children[nextChar] = newNext; | ||
| 42 | newNext.children[(int) next.relative.charAt(0)] = next; | ||
| 43 | insert(key, index + len, term); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | private int isPrefixOf(String key, int index) { | ||
| 49 | int i = 0; | ||
| 50 | for (int j = index; i < relative.length() && j < key.length(); ++i, ++j) | ||
| 51 | if (relative.charAt(i) != relative.charAt(j)) | ||
| 52 | break; | ||
| 53 | return i; | ||
| 54 | } | ||
| 55 | |||
| 56 | public Status find(String key, int index) { | ||
| 57 | TrieNode next = children[(int) key.charAt(index)]; | ||
| 58 | if (next == null) | ||
| 59 | return new Status(this, index, null); | ||
| 60 | |||
| 61 | if (next instanceof TrieLeaf) | ||
| 62 | if (next.relative.equals(key.substring(index))) | ||
| 63 | return new Status(this, index, ((TrieLeaf) next).term); | ||
| 64 | else { | ||
| 65 | return new Status(this, index, null); | ||
| 66 | } | ||
| 67 | return find(key, index + next.relative.length()); | ||
| 68 | } | ||
| 69 | |||
| 70 | } | ||
| 71 | |||
| 72 | class TrieLeaf extends TrieNode { | ||
| 73 | |||
| 74 | AnswerTerm term; | ||
| 75 | |||
| 76 | public TrieLeaf(String s, AnswerTerm term) { | ||
| 77 | super(s); | ||
| 78 | this.term = term; | ||
| 79 | } | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | class Status { | ||
| 84 | |||
| 85 | AnswerTerm term; | ||
| 86 | TrieNode lastNode; | ||
| 87 | int lastIndex; | ||
| 88 | |||
| 89 | public Status(TrieNode trieNode, int index, AnswerTerm term2) { | ||
| 90 | this.lastNode = trieNode; | ||
| 91 | this.lastIndex = index; | ||
| 92 | this.term = term2; | ||
| 93 | } | ||
| 94 | |||
| 95 | } \ No newline at end of file | ||
