JspellTagInterpreter implements TagInterpreter { public MorphologicalTag parseMorphologicalTag(String tagString) { if (tagString == null) { return null; } synchronized (cache) { if (cache.containsKey(tagString)) { return ((MorphologicalTag) cache.get(tagString)).clone(); } } MorphologicalTag m = new MorphologicalTag(); String[] tags = tagString.split(SEP); for (String tag : tags) { if (MTAG_PARTS_ENUM.containsKey(tag)) { List<Enum<?>> tagE = MTAG_PARTS_ENUM.get(tag); for (Enum<?> t : tagE) { if (t instanceof Class) { m.setClazz((Class) t); } else if (t instanceof Gender) { m.setGender((Gender) t); } else if (t instanceof Number) { m.setNumber((Number) t); } else if (t instanceof Case) { m.setCase((Case) t); } else if (t instanceof Person) { m.setPerson((Person) t); } else if (t instanceof Tense) { if (MOOD_INDICATIVE.contains(tag)) { m.setMood(Mood.INDICATIVE); } m.setTense((Tense) t); } else if (t instanceof Mood) { m.setMood((Mood) t); } else if (t instanceof Punctuation) { m.setPunctuation((Punctuation) t); } } } else { if (tag.startsWith("CAT:")) { if (tag.startsWith("CAT:punct")) { m.setClazz(Class.PUNCTUATION_MARK); } else if ("CAT:v".equals(tag) && m.getClazzE() == null) { m.setClazz(Class.FINITIVE_VERB); } else if ("CAT:ppos".equals(tag) || "CAT:pind".equals(tag) || "CAT:pdem".equals(tag) || "CAT:pint".equals(tag) || "CAT:prel".equals(tag)) { m.setClazz(Class.PRONOUN); } else if ("CAT:card".equals(tag) || "CAT:nord".equals(tag)) { m.setClazz(Class.NUMERAL); } else if (tag.startsWith("CAT:adj")) { m.setClazz(Class.ADJECTIVE); } else if ("CAT:cp".equals(tag) || "CAT:pass".equals(tag)) { return null; } } else if (tag.startsWith("T:")) { if (MOOD_INDICATIVE.contains(tag)) { m.setMood(Mood.INDICATIVE); } if ((Class.FINITIVE_VERB.equals(m.getClazzE()) || m.getClazzE() == null)) { if ("T:inf".equals(tag) || "T:ip".equals(tag)) { m.setClazz(Class.INFINITIVE_VERB); } else if ("T:ppa".equals(tag)) { m.setClazz(Class.PARTICIPLE_VERB); } else if ("T:g".equals(tag)) { m.setClazz(Class.GERUND_VERB); } } } else if (tag.length() == 1 || "--".equals(tag) || "...".equals(tag)) { m.setClazz(Class.PUNCTUATION_MARK); } else if ("n:".equals(tag)) { m.setClazz(Class.NOUN); } else if ("intj".equals(tag)) { m.setClazz(Class.INTERJECTION); } else if ("pp".equals(tag)) { m.setClazz(Class.PREPOSITION); } else if ("np".equals(tag)) { m.setClazz(Class.NOUN); } else { System.out.println(tag); } } } if (m.toString() == null || m.toString().length() == 0) { LOGGER.error("Invalid MorphologicalTag: " + tagString); } if (m.getGenderE() == null && m.getNumberE() != null) { if (Class.NOUN.equals(m.getClazzE()) || Class.NOUN_ADJECTIVE.equals(m.getClazzE()) || Class.NUMERAL.equals(m.getClazzE())) { m.setGender(Gender.NEUTRAL); } else if (Class.PROPER_NOUN.equals(m.getClazzE())) { m.setGender(Gender.MALE); } } if (m.getNumberE() == null && m.getGenderE() != null) { if (Class.NOUN.equals(m.getClazzE()) || Class.NOUN_ADJECTIVE.equals(m.getClazzE()) || Class.NUMERAL.equals(m.getClazzE())) { m.setNumber(Number.NEUTRAL); } else if (Class.PROPER_NOUN.equals(m.getClazzE())) { m.setNumber(Number.SINGULAR); } } if (m.getTense() != null && Class.NOUN.equals(m.getClazzE())) { m.setClazz(Class.INFINITIVE_VERB); } if(m == null || m.getClazzE() == null) { LOGGER.warn("something wrong with tag: " + tagString); } removeInvalidFeatures(m); synchronized (cache) { if (!cache.containsKey(tagString)) { cache.put(tagString, m.clone()); } } return m; } JspellTagInterpreter(); MorphologicalTag parseMorphologicalTag(String tagString); ChunkTag parseChunkTag(String tagString); SyntacticTag parseSyntacticTag(String tagString); String serialize(MorphologicalTag tag); String serialize(ChunkTag tag); String serialize(SyntacticTag tag); String serialize(SyntacticFunction tag); String serialize(ChunkFunction tag); String serialize(Class tag); String serialize(Gender tag); String serialize(Number tag); String serialize(Case tag); String serialize(Person tag); String serialize(Tense tag); String serialize(Mood tag); String serialize(Punctuation tag);  }
@Test public void testParseClassTag() { for (String tag : classTable.keySet()) { assertEquals("Failed to parse class tag: " + tag, classTable.get(tag), ti .parseMorphologicalTag(tag).getClazzE()); } assertNull(ti.parseMorphologicalTag("CAT:cp")); assertNull(ti.parseMorphologicalTag("CAT:pass")); }
@Test public void testParseNumberTag() { for (String tag : numTable.keySet()) { assertEquals("Failed to parse num tag: " + tag, numTable.get(tag), ti .parseMorphologicalTag(tag).getNumberE()); } }
@Test public void testParseGenderTag() { for (String tag : genTable.keySet()) { assertEquals("Failed to parse gen tag: " + tag, genTable.get(tag), ti .parseMorphologicalTag(tag).getGenderE()); } }
@Test public void testParsePersTag() { for (String tag : persTable.keySet()) { assertEquals("Failed to parse pers tag: " + tag, persTable.get(tag), ti .parseMorphologicalTag(tag).getPersonE()); } }
@Test public void testParseTenseTag() { for (String tag : tenseTable.keySet()) { assertEquals("Failed to parse tense tag: " + tag, tenseTable.get(tag), ti .parseMorphologicalTag(tag).getTense()); } }
@Test public void testCaseTenseTag() { for (String tag : caseTable.keySet()) { assertEquals("Failed to parse case tag: " + tag, caseTable.get(tag), ti .parseMorphologicalTag(tag).getCase()); } }
@Test public void testParseMoodTag() { for (String tag : moodTable.keySet()) { assertEquals("Failed to parse mood tag: " + tag, moodTable.get(tag), ti .parseMorphologicalTag(tag).getMood()); } }