public TagDictionary createTagDictionary(InputStream in) throws IOException { return POSDictionary.create(in); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof POSDictionary) { POSDictionary posDictionary = (POSDictionary) obj; if (this.dictionary.size() == posDictionary.dictionary.size()) { for (String word : this) { if (!Arrays.equals(getTags(word), posDictionary.getTags(word))) { return false; } } return true; } } return false; }
@Test public void testSerialization() throws IOException { POSDictionary dictionary = new POSDictionary(); dictionary.put("a", "1", "2", "3"); dictionary.put("b", "4", "5", "6"); dictionary.put("c", "7", "8", "9"); dictionary.put("Always", "RB","NNP"); Assert.assertTrue(dictionary.equals(serializeDeserializeDict(dictionary))); }
private static POSDictionary serializeDeserializeDict(POSDictionary dict) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { dict.serialize(out); } finally { out.close(); } POSDictionary serializedDictionary; try (InputStream in = new ByteArrayInputStream(out.toByteArray())) { serializedDictionary = POSDictionary.create(in); } return serializedDictionary; }
tagDictionary = POSDictionary.create(new FileInputStream(dictInFile)); } catch (IOException e) { throw new TerminateToolException(-1, "Error while loading XML POS Dictionay: " + e.getMessage(), e); Iterator<String> iterator = tagDictionary.iterator(); while (iterator.hasNext()) { String word = iterator.next(); for (String tag : tagDictionary.getTags(word)) { if (valid(word, tag)) { String entry = createEntry(word, tag);
public void serialize(POSDictionary artifact, OutputStream out) throws IOException { artifact.serialize(out); }
public TagDictionary createEmptyTagDictionary() { this.posDictionary = new POSDictionary(true); return this.posDictionary; } }
/** * Associates the specified tags with the specified word. If the dictionary * previously contained the word, the old tags are replaced by the specified * ones. * * @param word * The word to be added to the dictionary. * @param tags * The set of tags associated with the specified word. * * @deprecated Use {@link #put(String, String[])} instead */ void addTags(String word, String... tags) { put(word, tags); }
void addTags(String word, String... tags) { super.addTags(word, tags); for (String t : tags) { knwonTags.add(t); } }
tagDictionary = POSDictionary.create(new FileInputStream(dictInFile)); } catch (IOException e) { throw new TerminateToolException(-1, "Error while loading XML POS Dictionay: " + e.getMessage(), e); Iterator<String> iterator = tagDictionary.iterator(); while (iterator.hasNext()) { String word = iterator.next(); for (String tag : tagDictionary.getTags(word)) { if (valid(word, tag)) { String entry = createEntry(word, tag);
public void serialize(OutputStream out) throws IOException { dict.serialize(out); }
final POSDictionary newPosDict = new POSDictionary();
/** * Associates the specified tags with the specified word. If the dictionary * previously contained the word, the old tags are replaced by the specified * ones. * * @param word * The word to be added to the dictionary. * @param tags * The set of tags associated with the specified word. * * @deprecated Use {@link #put(String, String[])} instead */ void addTags(String word, String... tags) { put(word, tags); }
void addTags(String word, String... tags) { super.addTags(word, tags); for (String t : tags) { knwonTags.add(t); } }
@Override public int hashCode() { int[] keyHashes = new int[dictionary.size()]; int[] valueHashes = new int[dictionary.size()]; int i = 0; for (String word : this) { keyHashes[i] = word.hashCode(); valueHashes[i] = Arrays.hashCode(getTags(word)); i++; } Arrays.sort(keyHashes); Arrays.sort(valueHashes); return Objects.hash(Arrays.hashCode(keyHashes), Arrays.hashCode(valueHashes)); }
public POSDictionary create(InputStream in) throws IOException { return POSDictionary.create(new UncloseableInputStream(in)); }
public void serialize(POSDictionary artifact, OutputStream out) throws IOException { artifact.serialize(out); }
public TagDictionary createEmptyTagDictionary() { this.posDictionary = new POSDictionary(true); return this.posDictionary; } }
/** * Associates the specified tags with the specified word. If the dictionary * previously contained the word, the old tags are replaced by the specified * ones. * * @param word * The word to be added to the dictionary. * @param tags * The set of tags associated with the specified word. * * @deprecated Use {@link #put(String, String[])} instead */ void addTags(String word, String... tags) { put(word, tags); }
public String[] getTags(String word) { return dict.getTags(word); }