@Test public void shouldFormatDetailed() throws JSONException { { final MorphemeContainer result = getFirstParseResult("kitaba"); assertThat(MorphemeContainerFormatter.formatMorphemeContainerDetailed(result), equalTo("{\"Root\":\"kitab\",\"Parts\":[{\"POS\":\"Noun\",\"Suffixes\":[\"A3sg\",\"Pnon\",\"Dat\"]}],\"LemmaRoot\":\"kitap\",\"RootPos\":\"Noun\"}")); } { final MorphemeContainer result = getFirstParseResult("yaptırtmayı"); assertThat(MorphemeContainerFormatter.formatMorphemeContainerDetailed(result), equalTo("{\"Root\":\"yap\",\"Parts\":[{\"POS\":\"Verb\"},{\"POS\":\"Verb\",\"Suffixes\":[\"Caus\"]},{\"POS\":\"Verb\",\"Suffixes\":[\"Caus\",\"Pos\"]},{\"POS\":\"Noun\",\"Suffixes\":[\"Inf\",\"A3sg\",\"Pnon\",\"Acc\"]}],\"LemmaRoot\":\"yap\",\"RootPos\":\"Verb\"}")); } { final MorphemeContainer result = getFirstParseResult("üzümcülükteki"); assertThat(MorphemeContainerFormatter.formatMorphemeContainerDetailed(result), equalTo("{\"Root\":\"üzüm\",\"Parts\":[{\"POS\":\"Noun\",\"Suffixes\":[\"A3sg\",\"Pnon\",\"Nom\"]},{\"POS\":\"Adj\",\"Suffixes\":[\"Agt\"]},{\"POS\":\"Noun\",\"Suffixes\":[\"Ness\",\"A3sg\",\"Pnon\",\"Loc\"]},{\"POS\":\"Adj\",\"Suffixes\":[\"PointQual\"]}],\"LemmaRoot\":\"üzüm\",\"RootPos\":\"Noun\"}")); } { final MorphemeContainer result = getFirstParseResult("bu"); assertThat(MorphemeContainerFormatter.formatMorphemeContainerDetailed(result), equalTo("{\"Root\":\"bu\",\"LemmaRoot\":\"bu\",\"RootPos\":\"Det\"}")); } }
public static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer) { try { final List<JSONObject> parts = new ArrayList<JSONObject>(); JSONObject currentPart = null; List<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions(); for (int i = 0; i < suffixTransitions.size(); i++) { SuffixTransition suffixTransition = suffixTransitions.get(i); final Suffix suffix = suffixTransition.getSuffixFormApplication().getSuffixForm().getSuffix(); final SuffixGraphState targetState = suffixTransition.getTargetState(); final boolean isDerivational = suffixTransition.isDerivational(); if (isDerivational || i == 0) { if (currentPart != null) parts.add(currentPart); currentPart = new JSONObject(); final String currentPos = targetState.getPrimaryPos().getStringForm(); final SecondaryPos currentSecondaryPos = targetState.getSecondaryPos(); final String currentSpos = currentSecondaryPos == null ? null : currentSecondaryPos.getStringForm(); currentPart.put("POS", currentPos); if (StringUtils.isNotBlank(currentSpos)) currentPart.put("SPOS", currentSpos); } if (suffix instanceof FreeTransitionSuffix || suffix instanceof ConditionalFreeTransitionSuffix) continue; JSONArray suffixes; if (currentPart.has("Suffixes")) { suffixes = currentPart.getJSONArray("Suffixes"); } else { suffixes = new JSONArray(); currentPart.put("Suffixes", suffixes); } suffixes.put(suffix.getPrettyName()); } if (currentPart != null) parts.add(currentPart); final Lexeme lexeme = morphemeContainer.getRoot().getLexeme(); final String rootStr = morphemeContainer.getRoot().getSequence().getUnderlyingString(); final String lemmaRoot = lexeme.getLemmaRoot(); final PrimaryPos primaryPos = lexeme.getPrimaryPos(); final SecondaryPos secondaryPos = lexeme.getSecondaryPos(); final JSONObject parentObject = new JSONObject(); parentObject.put("Root", rootStr); parentObject.put("LemmaRoot", lemmaRoot); parentObject.put("RootPos", primaryPos.getStringForm()); if (secondaryPos != null) parentObject.put("RootSpos", secondaryPos.getStringForm()); if (CollectionUtils.isNotEmpty(parts)) parentObject.put("Parts", parts); return parentObject.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
MorphemeContainerFormatter { public static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer) { try { final List<JSONObject> parts = new ArrayList<JSONObject>(); JSONObject currentPart = null; List<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions(); for (int i = 0; i < suffixTransitions.size(); i++) { SuffixTransition suffixTransition = suffixTransitions.get(i); final Suffix suffix = suffixTransition.getSuffixFormApplication().getSuffixForm().getSuffix(); final SuffixGraphState targetState = suffixTransition.getTargetState(); final boolean isDerivational = suffixTransition.isDerivational(); if (isDerivational || i == 0) { if (currentPart != null) parts.add(currentPart); currentPart = new JSONObject(); final String currentPos = targetState.getPrimaryPos().getStringForm(); final SecondaryPos currentSecondaryPos = targetState.getSecondaryPos(); final String currentSpos = currentSecondaryPos == null ? null : currentSecondaryPos.getStringForm(); currentPart.put("POS", currentPos); if (StringUtils.isNotBlank(currentSpos)) currentPart.put("SPOS", currentSpos); } if (suffix instanceof FreeTransitionSuffix || suffix instanceof ConditionalFreeTransitionSuffix) continue; JSONArray suffixes; if (currentPart.has("Suffixes")) { suffixes = currentPart.getJSONArray("Suffixes"); } else { suffixes = new JSONArray(); currentPart.put("Suffixes", suffixes); } suffixes.put(suffix.getPrettyName()); } if (currentPart != null) parts.add(currentPart); final Lexeme lexeme = morphemeContainer.getRoot().getLexeme(); final String rootStr = morphemeContainer.getRoot().getSequence().getUnderlyingString(); final String lemmaRoot = lexeme.getLemmaRoot(); final PrimaryPos primaryPos = lexeme.getPrimaryPos(); final SecondaryPos secondaryPos = lexeme.getSecondaryPos(); final JSONObject parentObject = new JSONObject(); parentObject.put("Root", rootStr); parentObject.put("LemmaRoot", lemmaRoot); parentObject.put("RootPos", primaryPos.getStringForm()); if (secondaryPos != null) parentObject.put("RootSpos", secondaryPos.getStringForm()); if (CollectionUtils.isNotEmpty(parts)) parentObject.put("Parts", parts); return parentObject.toString(); } catch (Exception e) { throw new RuntimeException(e); } } }
MorphemeContainerFormatter { public static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer) { try { final List<JSONObject> parts = new ArrayList<JSONObject>(); JSONObject currentPart = null; List<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions(); for (int i = 0; i < suffixTransitions.size(); i++) { SuffixTransition suffixTransition = suffixTransitions.get(i); final Suffix suffix = suffixTransition.getSuffixFormApplication().getSuffixForm().getSuffix(); final SuffixGraphState targetState = suffixTransition.getTargetState(); final boolean isDerivational = suffixTransition.isDerivational(); if (isDerivational || i == 0) { if (currentPart != null) parts.add(currentPart); currentPart = new JSONObject(); final String currentPos = targetState.getPrimaryPos().getStringForm(); final SecondaryPos currentSecondaryPos = targetState.getSecondaryPos(); final String currentSpos = currentSecondaryPos == null ? null : currentSecondaryPos.getStringForm(); currentPart.put("POS", currentPos); if (StringUtils.isNotBlank(currentSpos)) currentPart.put("SPOS", currentSpos); } if (suffix instanceof FreeTransitionSuffix || suffix instanceof ConditionalFreeTransitionSuffix) continue; JSONArray suffixes; if (currentPart.has("Suffixes")) { suffixes = currentPart.getJSONArray("Suffixes"); } else { suffixes = new JSONArray(); currentPart.put("Suffixes", suffixes); } suffixes.put(suffix.getPrettyName()); } if (currentPart != null) parts.add(currentPart); final Lexeme lexeme = morphemeContainer.getRoot().getLexeme(); final String rootStr = morphemeContainer.getRoot().getSequence().getUnderlyingString(); final String lemmaRoot = lexeme.getLemmaRoot(); final PrimaryPos primaryPos = lexeme.getPrimaryPos(); final SecondaryPos secondaryPos = lexeme.getSecondaryPos(); final JSONObject parentObject = new JSONObject(); parentObject.put("Root", rootStr); parentObject.put("LemmaRoot", lemmaRoot); parentObject.put("RootPos", primaryPos.getStringForm()); if (secondaryPos != null) parentObject.put("RootSpos", secondaryPos.getStringForm()); if (CollectionUtils.isNotEmpty(parts)) parentObject.put("Parts", parts); return parentObject.toString(); } catch (Exception e) { throw new RuntimeException(e); } }  }
MorphemeContainerFormatter { public static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer) { try { final List<JSONObject> parts = new ArrayList<JSONObject>(); JSONObject currentPart = null; List<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions(); for (int i = 0; i < suffixTransitions.size(); i++) { SuffixTransition suffixTransition = suffixTransitions.get(i); final Suffix suffix = suffixTransition.getSuffixFormApplication().getSuffixForm().getSuffix(); final SuffixGraphState targetState = suffixTransition.getTargetState(); final boolean isDerivational = suffixTransition.isDerivational(); if (isDerivational || i == 0) { if (currentPart != null) parts.add(currentPart); currentPart = new JSONObject(); final String currentPos = targetState.getPrimaryPos().getStringForm(); final SecondaryPos currentSecondaryPos = targetState.getSecondaryPos(); final String currentSpos = currentSecondaryPos == null ? null : currentSecondaryPos.getStringForm(); currentPart.put("POS", currentPos); if (StringUtils.isNotBlank(currentSpos)) currentPart.put("SPOS", currentSpos); } if (suffix instanceof FreeTransitionSuffix || suffix instanceof ConditionalFreeTransitionSuffix) continue; JSONArray suffixes; if (currentPart.has("Suffixes")) { suffixes = currentPart.getJSONArray("Suffixes"); } else { suffixes = new JSONArray(); currentPart.put("Suffixes", suffixes); } suffixes.put(suffix.getPrettyName()); } if (currentPart != null) parts.add(currentPart); final Lexeme lexeme = morphemeContainer.getRoot().getLexeme(); final String rootStr = morphemeContainer.getRoot().getSequence().getUnderlyingString(); final String lemmaRoot = lexeme.getLemmaRoot(); final PrimaryPos primaryPos = lexeme.getPrimaryPos(); final SecondaryPos secondaryPos = lexeme.getSecondaryPos(); final JSONObject parentObject = new JSONObject(); parentObject.put("Root", rootStr); parentObject.put("LemmaRoot", lemmaRoot); parentObject.put("RootPos", primaryPos.getStringForm()); if (secondaryPos != null) parentObject.put("RootSpos", secondaryPos.getStringForm()); if (CollectionUtils.isNotEmpty(parts)) parentObject.put("Parts", parts); return parentObject.toString(); } catch (Exception e) { throw new RuntimeException(e); } }  static String formatMorphemeContainer(final MorphemeContainer morphemeContainer); @SuppressWarnings("UnusedDeclaration") static Collection<String> formatMorphemeContainers(final Collection<MorphemeContainer> morphemeContainers); static List<String> formatMorphemeContainers(final List<MorphemeContainer> morphemeContainers); static String formatMorphemeContainerWithForms(final MorphemeContainer morphemeContainer); static String formatMorphemeContainerWithDerivationGrouping(MorphemeContainer morphemeContainer); static String formatMorphemeContainerWithDerivationGrouping(MorphemeContainer morphemeContainer, boolean addIndices); static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer); static Collection<String> formatMorphemeContainersWithDerivationGrouping(Collection<MorphemeContainer> morphemeContainers); }
MorphemeContainerFormatter { public static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer) { try { final List<JSONObject> parts = new ArrayList<JSONObject>(); JSONObject currentPart = null; List<SuffixTransition> suffixTransitions = morphemeContainer.getSuffixTransitions(); for (int i = 0; i < suffixTransitions.size(); i++) { SuffixTransition suffixTransition = suffixTransitions.get(i); final Suffix suffix = suffixTransition.getSuffixFormApplication().getSuffixForm().getSuffix(); final SuffixGraphState targetState = suffixTransition.getTargetState(); final boolean isDerivational = suffixTransition.isDerivational(); if (isDerivational || i == 0) { if (currentPart != null) parts.add(currentPart); currentPart = new JSONObject(); final String currentPos = targetState.getPrimaryPos().getStringForm(); final SecondaryPos currentSecondaryPos = targetState.getSecondaryPos(); final String currentSpos = currentSecondaryPos == null ? null : currentSecondaryPos.getStringForm(); currentPart.put("POS", currentPos); if (StringUtils.isNotBlank(currentSpos)) currentPart.put("SPOS", currentSpos); } if (suffix instanceof FreeTransitionSuffix || suffix instanceof ConditionalFreeTransitionSuffix) continue; JSONArray suffixes; if (currentPart.has("Suffixes")) { suffixes = currentPart.getJSONArray("Suffixes"); } else { suffixes = new JSONArray(); currentPart.put("Suffixes", suffixes); } suffixes.put(suffix.getPrettyName()); } if (currentPart != null) parts.add(currentPart); final Lexeme lexeme = morphemeContainer.getRoot().getLexeme(); final String rootStr = morphemeContainer.getRoot().getSequence().getUnderlyingString(); final String lemmaRoot = lexeme.getLemmaRoot(); final PrimaryPos primaryPos = lexeme.getPrimaryPos(); final SecondaryPos secondaryPos = lexeme.getSecondaryPos(); final JSONObject parentObject = new JSONObject(); parentObject.put("Root", rootStr); parentObject.put("LemmaRoot", lemmaRoot); parentObject.put("RootPos", primaryPos.getStringForm()); if (secondaryPos != null) parentObject.put("RootSpos", secondaryPos.getStringForm()); if (CollectionUtils.isNotEmpty(parts)) parentObject.put("Parts", parts); return parentObject.toString(); } catch (Exception e) { throw new RuntimeException(e); } }  static String formatMorphemeContainer(final MorphemeContainer morphemeContainer); @SuppressWarnings("UnusedDeclaration") static Collection<String> formatMorphemeContainers(final Collection<MorphemeContainer> morphemeContainers); static List<String> formatMorphemeContainers(final List<MorphemeContainer> morphemeContainers); static String formatMorphemeContainerWithForms(final MorphemeContainer morphemeContainer); static String formatMorphemeContainerWithDerivationGrouping(MorphemeContainer morphemeContainer); static String formatMorphemeContainerWithDerivationGrouping(MorphemeContainer morphemeContainer, boolean addIndices); static String formatMorphemeContainerDetailed(MorphemeContainer morphemeContainer); static Collection<String> formatMorphemeContainersWithDerivationGrouping(Collection<MorphemeContainer> morphemeContainers);  }