From a3863405712317736abc598dc3f6327cad4cc10d Mon Sep 17 00:00:00 2001 From: Thora Daneyko Date: Fri, 13 Dec 2019 14:55:21 +0100 Subject: [PATCH] Restructured subpackages --- src/main/java/de/tuebingen/sfs/jfst/Demo.java | 55 ------------------- .../sfs/jfst/{ => alphabet}/Alphabet.java | 32 +++++------ .../sfs/jfst/{ => alphabet}/CharSymbol.java | 2 +- .../jfst/{ => alphabet}/MulticharSymbol.java | 2 +- .../sfs/jfst/{ => alphabet}/Symbol.java | 2 +- .../sfs/jfst/{ => fst}/CompactFST.java | 6 +- .../de/tuebingen/sfs/jfst/{ => fst}/FST.java | 2 +- .../sfs/jfst/{ => fst}/FSTStateIterator.java | 4 +- .../sfs/jfst/{ => fst}/MutableFST.java | 6 +- .../sfs/jfst/{ => io}/BinaryFSTWriter.java | 4 +- .../jfst/{ => io}/FSTFileStateIterator.java | 4 +- .../sfs/jfst/{ => io}/FSTProducer.java | 4 +- .../jfst/{ => io}/HFSTFileStateIterator.java | 4 +- .../jfst/{ => io}/JFSTFileStateIterator.java | 4 +- 14 files changed, 48 insertions(+), 83 deletions(-) delete mode 100644 src/main/java/de/tuebingen/sfs/jfst/Demo.java rename src/main/java/de/tuebingen/sfs/jfst/{ => alphabet}/Alphabet.java (88%) rename src/main/java/de/tuebingen/sfs/jfst/{ => alphabet}/CharSymbol.java (98%) rename src/main/java/de/tuebingen/sfs/jfst/{ => alphabet}/MulticharSymbol.java (98%) rename src/main/java/de/tuebingen/sfs/jfst/{ => alphabet}/Symbol.java (98%) rename src/main/java/de/tuebingen/sfs/jfst/{ => fst}/CompactFST.java (99%) rename src/main/java/de/tuebingen/sfs/jfst/{ => fst}/FST.java (98%) rename src/main/java/de/tuebingen/sfs/jfst/{ => fst}/FSTStateIterator.java (95%) rename src/main/java/de/tuebingen/sfs/jfst/{ => fst}/MutableFST.java (99%) rename src/main/java/de/tuebingen/sfs/jfst/{ => io}/BinaryFSTWriter.java (97%) rename src/main/java/de/tuebingen/sfs/jfst/{ => io}/FSTFileStateIterator.java (50%) rename src/main/java/de/tuebingen/sfs/jfst/{ => io}/FSTProducer.java (96%) rename src/main/java/de/tuebingen/sfs/jfst/{ => io}/HFSTFileStateIterator.java (98%) rename src/main/java/de/tuebingen/sfs/jfst/{ => io}/JFSTFileStateIterator.java (98%) diff --git a/src/main/java/de/tuebingen/sfs/jfst/Demo.java b/src/main/java/de/tuebingen/sfs/jfst/Demo.java deleted file mode 100644 index 5f08ca6..0000000 --- a/src/main/java/de/tuebingen/sfs/jfst/Demo.java +++ /dev/null @@ -1,55 +0,0 @@ -package de.tuebingen.sfs.jfst; - -import java.io.*; - -class Demo { - public static void main(String[] args) { - Runtime r = Runtime.getRuntime(); - long memBefore = r.totalMemory() - r.freeMemory(); - long timBefore = System.currentTimeMillis(); -// MutableFST fst = null; -// try { -// fst = new MutableFST(new FileInputStream(new File("src/test/resources/zmorge.att")), FSTProducer.SFST, true); -// } catch (FileNotFoundException e) { -// e.printStackTrace(); -// } - long timAfter = System.currentTimeMillis(); -// r.gc(); - long memAfter = r.totalMemory() - r.freeMemory(); -// System.err.println("AT&T Time: " + (timAfter - timBefore)); -// System.err.println("AT&T Memory: " + (memAfter - memBefore)); -// for (String s : fst.apply("mich")) -// System.err.println(s); -// for (String s : fst.apply("Vermittlungsgespräche")) -// System.err.println(s); -// for (String s : fst.apply("überragenderen")) -// System.err.println(s); -// -// try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File("src/test/resources/zmorge.jfst")))) { -// fst.writeToBinary(out); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// r.gc(); - - memBefore = r.totalMemory() - r.freeMemory(); - timBefore = System.currentTimeMillis(); - CompactFST fst2 = CompactFST.readFromBinary("/zmorge.jfst"); - timAfter = System.currentTimeMillis(); - r.gc(); - memAfter = r.totalMemory() - r.freeMemory(); - System.err.println("JFST Time: " + (timAfter - timBefore)); - System.err.println("JFST Memory: " + (memAfter - memBefore)); - for (String s : fst2.apply("mich")) - System.err.println(s); - for (String s : fst2.apply("Vermittlungsgespräche")) - System.err.println(s); - for (String s : fst2.apply("ging")) - System.err.println(s); - timBefore = System.currentTimeMillis(); - for (String s : fst2.apply("überragenderen")) - System.err.println(s); - timAfter = System.currentTimeMillis(); - System.err.println("Lookup Time: " + (timAfter - timBefore)); - } -} diff --git a/src/main/java/de/tuebingen/sfs/jfst/Alphabet.java b/src/main/java/de/tuebingen/sfs/jfst/alphabet/Alphabet.java similarity index 88% rename from src/main/java/de/tuebingen/sfs/jfst/Alphabet.java rename to src/main/java/de/tuebingen/sfs/jfst/alphabet/Alphabet.java index 2f2e915..cff6c5f 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/Alphabet.java +++ b/src/main/java/de/tuebingen/sfs/jfst/alphabet/Alphabet.java @@ -1,4 +1,4 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.alphabet; import java.util.*; @@ -20,7 +20,7 @@ public class Alphabet { /** * Create an empty Alphabet. */ - Alphabet() { + public Alphabet() { alphabet = new ArrayList<>(); id2sym = new ArrayList<>(); } @@ -28,7 +28,7 @@ public class Alphabet { /** * Create an Alphabet with symbols. */ - Alphabet(String[] symbols) { + public Alphabet(String[] symbols) { this(); addSymbols(symbols); } @@ -36,7 +36,7 @@ public class Alphabet { /** * Create an Alphabet with symbols. */ - Alphabet(Iterable symbols) { + public Alphabet(Iterable symbols) { this(); addSymbols(symbols); } @@ -46,7 +46,7 @@ public class Alphabet { * @param symbol A char symbol * @return True if this Alphabet already contains the symbol */ - boolean contains(char symbol) { + public boolean contains(char symbol) { return Collections.binarySearch(alphabet, symbol) >= 0; } @@ -55,7 +55,7 @@ boolean contains(char symbol) { * @param symbol A string symbol * @return True if this Alphabet already contains the symbol */ - boolean contains(String symbol) { + public boolean contains(String symbol) { return Collections.binarySearch(alphabet, symbol) >= 0; } @@ -65,7 +65,7 @@ boolean contains(String symbol) { * @param symbol A string symbol * @return The Symbol object associated with this string */ - Symbol getSymbol(String symbol) { + public Symbol getSymbol(String symbol) { int i = Collections.binarySearch(alphabet, symbol); if (i < 0) { i = -(i+1); @@ -80,14 +80,14 @@ Symbol getSymbol(String symbol) { * @param id An id * @return The symbol with this id or null if there is no such symbol */ - Symbol getSymbol(int id) { + public Symbol getSymbol(int id) { if (id < id2sym.size()) return id2sym.get(id); else return null; } - void setSymbol(int id, String symbol) { + private void setSymbol(int id, String symbol) { if (id >= id2sym.size()) addSymbol(symbol); else { @@ -99,7 +99,7 @@ void setSymbol(int id, String symbol) { } } - List getPrefixes(String s, int start) { + public List getPrefixes(String s, int start) { List prefixes = new ArrayList<>(); char c = s.charAt(start); // int i = Collections.binarySearch(alphabet, c); @@ -121,7 +121,7 @@ List getPrefixes(String s, int start) { * Add a symbol to the alphabet. Calls getSymbol() internally. * @param symbol A symbol */ - void addSymbol(String symbol) { + public void addSymbol(String symbol) { getSymbol(symbol); } @@ -129,7 +129,7 @@ void addSymbol(String symbol) { * Add multiple symbols to the alphabet. Calls getSymbol() internally. * @param symbols An array of symbols */ - void addSymbols(String[] symbols) { + public void addSymbols(String[] symbols) { int i = 0; for (String sym : symbols) { if (sym == null) @@ -143,7 +143,7 @@ void addSymbols(String[] symbols) { * Add multiple symbols to the alphabet. Calls getSymbol() internally. * @param symbols A list of symbols */ - void addSymbols(Iterable symbols) { + public void addSymbols(Iterable symbols) { for (String sym : symbols) { if (sym == null) addSymbol("NULL"); @@ -174,7 +174,7 @@ private Symbol createSymbol(String symbol, int id) { * Get the string representations of all symbols in this alphabet as an array, ordered according to their id. * @return An array with all symols in this alphabet */ - String[] getSymbols() { + public String[] getSymbols() { return id2sym.stream().map(Symbol::asString).toArray(String[]::new); } @@ -183,7 +183,7 @@ String[] getSymbols() { * @param symbol A string symbol * @return The id of the symbol in this alphabet, or -1 if it is not contained */ - int idOf(String symbol) { + public int idOf(String symbol) { return (contains(symbol)) ? getSymbol(symbol).getId() : -1; } @@ -191,7 +191,7 @@ int idOf(String symbol) { * Get the total number of symbols in this alphabet. * @return The size of this alphabet */ - int size() { + public int size() { return alphabet.size(); } diff --git a/src/main/java/de/tuebingen/sfs/jfst/CharSymbol.java b/src/main/java/de/tuebingen/sfs/jfst/alphabet/CharSymbol.java similarity index 98% rename from src/main/java/de/tuebingen/sfs/jfst/CharSymbol.java rename to src/main/java/de/tuebingen/sfs/jfst/alphabet/CharSymbol.java index 8bfe593..d3204be 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/CharSymbol.java +++ b/src/main/java/de/tuebingen/sfs/jfst/alphabet/CharSymbol.java @@ -1,4 +1,4 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.alphabet; /** * A symbol consisting of a single character. diff --git a/src/main/java/de/tuebingen/sfs/jfst/MulticharSymbol.java b/src/main/java/de/tuebingen/sfs/jfst/alphabet/MulticharSymbol.java similarity index 98% rename from src/main/java/de/tuebingen/sfs/jfst/MulticharSymbol.java rename to src/main/java/de/tuebingen/sfs/jfst/alphabet/MulticharSymbol.java index 86bed3f..e96a685 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/MulticharSymbol.java +++ b/src/main/java/de/tuebingen/sfs/jfst/alphabet/MulticharSymbol.java @@ -1,4 +1,4 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.alphabet; /** * A symbol consisting of multiple characters. diff --git a/src/main/java/de/tuebingen/sfs/jfst/Symbol.java b/src/main/java/de/tuebingen/sfs/jfst/alphabet/Symbol.java similarity index 98% rename from src/main/java/de/tuebingen/sfs/jfst/Symbol.java rename to src/main/java/de/tuebingen/sfs/jfst/alphabet/Symbol.java index 61b5364..c16f526 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/Symbol.java +++ b/src/main/java/de/tuebingen/sfs/jfst/alphabet/Symbol.java @@ -1,4 +1,4 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.alphabet; /** * A symbol in the alphabet of an FST. diff --git a/src/main/java/de/tuebingen/sfs/jfst/CompactFST.java b/src/main/java/de/tuebingen/sfs/jfst/fst/CompactFST.java similarity index 99% rename from src/main/java/de/tuebingen/sfs/jfst/CompactFST.java rename to src/main/java/de/tuebingen/sfs/jfst/fst/CompactFST.java index f904377..5ce0092 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/CompactFST.java +++ b/src/main/java/de/tuebingen/sfs/jfst/fst/CompactFST.java @@ -1,4 +1,8 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.fst; + +import de.tuebingen.sfs.jfst.alphabet.Alphabet; +import de.tuebingen.sfs.jfst.alphabet.Symbol; +import de.tuebingen.sfs.jfst.io.*; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/de/tuebingen/sfs/jfst/FST.java b/src/main/java/de/tuebingen/sfs/jfst/fst/FST.java similarity index 98% rename from src/main/java/de/tuebingen/sfs/jfst/FST.java rename to src/main/java/de/tuebingen/sfs/jfst/fst/FST.java index e1a56ea..ebe0d28 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/FST.java +++ b/src/main/java/de/tuebingen/sfs/jfst/fst/FST.java @@ -1,4 +1,4 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.fst; import java.io.IOException; import java.io.OutputStream; diff --git a/src/main/java/de/tuebingen/sfs/jfst/FSTStateIterator.java b/src/main/java/de/tuebingen/sfs/jfst/fst/FSTStateIterator.java similarity index 95% rename from src/main/java/de/tuebingen/sfs/jfst/FSTStateIterator.java rename to src/main/java/de/tuebingen/sfs/jfst/fst/FSTStateIterator.java index 8f8eb09..122e658 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/FSTStateIterator.java +++ b/src/main/java/de/tuebingen/sfs/jfst/fst/FSTStateIterator.java @@ -1,4 +1,6 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.fst; + +import de.tuebingen.sfs.jfst.alphabet.Alphabet; /** * An iterator over the states and transitions of an FST. diff --git a/src/main/java/de/tuebingen/sfs/jfst/MutableFST.java b/src/main/java/de/tuebingen/sfs/jfst/fst/MutableFST.java similarity index 99% rename from src/main/java/de/tuebingen/sfs/jfst/MutableFST.java rename to src/main/java/de/tuebingen/sfs/jfst/fst/MutableFST.java index 8ecce3a..421875a 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/MutableFST.java +++ b/src/main/java/de/tuebingen/sfs/jfst/fst/MutableFST.java @@ -1,5 +1,9 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.fst; +import de.tuebingen.sfs.jfst.io.FSTProducer; +import de.tuebingen.sfs.jfst.alphabet.Alphabet; +import de.tuebingen.sfs.jfst.alphabet.Symbol; +import de.tuebingen.sfs.jfst.io.BinaryFSTWriter; import de.tuebingen.sfs.util.string.StringUtils; import de.tuebingen.sfs.util.bin.BufferedByteReader; import de.tuebingen.sfs.util.bin.IOUtils; diff --git a/src/main/java/de/tuebingen/sfs/jfst/BinaryFSTWriter.java b/src/main/java/de/tuebingen/sfs/jfst/io/BinaryFSTWriter.java similarity index 97% rename from src/main/java/de/tuebingen/sfs/jfst/BinaryFSTWriter.java rename to src/main/java/de/tuebingen/sfs/jfst/io/BinaryFSTWriter.java index 43a8cc2..91c8dae 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/BinaryFSTWriter.java +++ b/src/main/java/de/tuebingen/sfs/jfst/io/BinaryFSTWriter.java @@ -1,5 +1,7 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.io; +import de.tuebingen.sfs.jfst.fst.FST; +import de.tuebingen.sfs.jfst.fst.FSTStateIterator; import de.tuebingen.sfs.util.bin.IOUtils; import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; diff --git a/src/main/java/de/tuebingen/sfs/jfst/FSTFileStateIterator.java b/src/main/java/de/tuebingen/sfs/jfst/io/FSTFileStateIterator.java similarity index 50% rename from src/main/java/de/tuebingen/sfs/jfst/FSTFileStateIterator.java rename to src/main/java/de/tuebingen/sfs/jfst/io/FSTFileStateIterator.java index ba4f009..dd94512 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/FSTFileStateIterator.java +++ b/src/main/java/de/tuebingen/sfs/jfst/io/FSTFileStateIterator.java @@ -1,4 +1,6 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.io; + +import de.tuebingen.sfs.jfst.fst.FSTStateIterator; public interface FSTFileStateIterator extends FSTStateIterator { diff --git a/src/main/java/de/tuebingen/sfs/jfst/FSTProducer.java b/src/main/java/de/tuebingen/sfs/jfst/io/FSTProducer.java similarity index 96% rename from src/main/java/de/tuebingen/sfs/jfst/FSTProducer.java rename to src/main/java/de/tuebingen/sfs/jfst/io/FSTProducer.java index 29a67ae..b671679 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/FSTProducer.java +++ b/src/main/java/de/tuebingen/sfs/jfst/io/FSTProducer.java @@ -1,4 +1,6 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.io; + +import de.tuebingen.sfs.jfst.alphabet.Symbol; /** * The original producer of a file. Currently supports SFST, HFST and JFST. diff --git a/src/main/java/de/tuebingen/sfs/jfst/HFSTFileStateIterator.java b/src/main/java/de/tuebingen/sfs/jfst/io/HFSTFileStateIterator.java similarity index 98% rename from src/main/java/de/tuebingen/sfs/jfst/HFSTFileStateIterator.java rename to src/main/java/de/tuebingen/sfs/jfst/io/HFSTFileStateIterator.java index fc4deba..8646f75 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/HFSTFileStateIterator.java +++ b/src/main/java/de/tuebingen/sfs/jfst/io/HFSTFileStateIterator.java @@ -1,5 +1,7 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.io; +import de.tuebingen.sfs.jfst.alphabet.Alphabet; +import de.tuebingen.sfs.jfst.alphabet.Symbol; import de.tuebingen.sfs.util.bin.BufferedByteReader; import java.io.IOException; diff --git a/src/main/java/de/tuebingen/sfs/jfst/JFSTFileStateIterator.java b/src/main/java/de/tuebingen/sfs/jfst/io/JFSTFileStateIterator.java similarity index 98% rename from src/main/java/de/tuebingen/sfs/jfst/JFSTFileStateIterator.java rename to src/main/java/de/tuebingen/sfs/jfst/io/JFSTFileStateIterator.java index f1e3f61..9446269 100644 --- a/src/main/java/de/tuebingen/sfs/jfst/JFSTFileStateIterator.java +++ b/src/main/java/de/tuebingen/sfs/jfst/io/JFSTFileStateIterator.java @@ -1,5 +1,7 @@ -package de.tuebingen.sfs.jfst; +package de.tuebingen.sfs.jfst.io; +import de.tuebingen.sfs.jfst.alphabet.Alphabet; +import de.tuebingen.sfs.jfst.alphabet.Symbol; import de.tuebingen.sfs.util.bin.BufferedByteReader; import de.tuebingen.sfs.util.bin.IOUtils; import gnu.trove.list.TIntList;