@Test public void testColorCoderNoHits() { final String colorClass = new ColorCoderProviderImpl(this.mockManager).getColorClass("robinson:def"); assertEquals("", colorClass); }
public String getColorClass(final String morph) { if (morph == null || morph.length() < MINIMUM_MORPH_LENGTH) { return ""; } String classes = null; if (morph.startsWith(ROBINSON_PREFIX_LC) || morph.startsWith(ROBINSON_PREFIX_UC)) { LOGGER.debug("Identifying grammar for [{}]", morph); final int length = ROBINSON_PREFIX_LC.length(); final int firstSpace = morph.indexOf(' ', length); String code; if (firstSpace != -1) { code = morph.substring(length, firstSpace); } else { code = morph.substring(length); } final EntityDoc[] results = this.morphology.searchExactTermBySingleField("code", 1, code); if (results.length > 0) { classes = results[0].get("cssClasses"); String funct; try { funct = results[0].get("function").toLowerCase(); } catch (NullPointerException e) { funct = ""; } if (funct.equals("verb")) { String tense, voice, mood; try { tense = results[0].get("tense").toLowerCase(); voice = results[0].get("voice").toLowerCase(); mood = results[0].get("mood").toLowerCase(); } catch (NullPointerException e) { tense = voice = mood = ""; } if (!tense.isEmpty() && !mood.isEmpty()) { if (tense.startsWith("2nd ")) { tense = tense.substring(4); } else if (tense.equals("indefinite tense")) { tense = "indefinite"; } if ( (voice.equals("passive")) || (voice.equals("either middle or passive")) ) { voice = "p"; } else if (voice.equals("middle") ) { voice = "m"; } else if ((voice.indexOf("active") > -1) || (voice.indexOf("deponent") > -1) || (voice.indexOf("indefinite") > -1) ) { voice = "a"; } else { LOGGER.warn("cannot identify voice [{}]", voice); voice = "a"; } classes = classes + " v" + getShortCodeTense(tense) + voice + getShortCodeMood(mood); } } } else if (code.length() > 4) { if (code.substring(0,1).equalsIgnoreCase("v")) { String tense = code.substring(2,3).toLowerCase(); String voice = code.substring(3,4).toLowerCase(); String mood = code.substring(4,5).toLowerCase(); if (tense.equals("2")) { tense = code.substring(3,4).toLowerCase(); voice = code.substring(4,5).toLowerCase(); mood = code.substring(5,6).toLowerCase(); } if (voice.equals("e")) { voice = "p"; } else if ( (!(voice.equals("p"))) && (!(voice.equals("m"))) ) { String voice_displayed_as_active = "adnoqx"; if (voice_displayed_as_active.indexOf(voice) == -1) { LOGGER.warn("cannot identify morphology for [{}]", code); } voice = "a"; } classes = "v" + tense + voice + mood; if (classes == null) { LOGGER.warn("cannot identify morphology for [{}]", code); } } else { LOGGER.warn("other than verb [{}]", code); } } if (isBlank(classes) && firstSpace != -1) { return getColorClass(morph.substring(firstSpace + 1)); } } return classes != null ? classes : ""; }
ColorCoderProviderImpl { public String getColorClass(final String morph) { if (morph == null || morph.length() < MINIMUM_MORPH_LENGTH) { return ""; } String classes = null; if (morph.startsWith(ROBINSON_PREFIX_LC) || morph.startsWith(ROBINSON_PREFIX_UC)) { LOGGER.debug("Identifying grammar for [{}]", morph); final int length = ROBINSON_PREFIX_LC.length(); final int firstSpace = morph.indexOf(' ', length); String code; if (firstSpace != -1) { code = morph.substring(length, firstSpace); } else { code = morph.substring(length); } final EntityDoc[] results = this.morphology.searchExactTermBySingleField("code", 1, code); if (results.length > 0) { classes = results[0].get("cssClasses"); String funct; try { funct = results[0].get("function").toLowerCase(); } catch (NullPointerException e) { funct = ""; } if (funct.equals("verb")) { String tense, voice, mood; try { tense = results[0].get("tense").toLowerCase(); voice = results[0].get("voice").toLowerCase(); mood = results[0].get("mood").toLowerCase(); } catch (NullPointerException e) { tense = voice = mood = ""; } if (!tense.isEmpty() && !mood.isEmpty()) { if (tense.startsWith("2nd ")) { tense = tense.substring(4); } else if (tense.equals("indefinite tense")) { tense = "indefinite"; } if ( (voice.equals("passive")) || (voice.equals("either middle or passive")) ) { voice = "p"; } else if (voice.equals("middle") ) { voice = "m"; } else if ((voice.indexOf("active") > -1) || (voice.indexOf("deponent") > -1) || (voice.indexOf("indefinite") > -1) ) { voice = "a"; } else { LOGGER.warn("cannot identify voice [{}]", voice); voice = "a"; } classes = classes + " v" + getShortCodeTense(tense) + voice + getShortCodeMood(mood); } } } else if (code.length() > 4) { if (code.substring(0,1).equalsIgnoreCase("v")) { String tense = code.substring(2,3).toLowerCase(); String voice = code.substring(3,4).toLowerCase(); String mood = code.substring(4,5).toLowerCase(); if (tense.equals("2")) { tense = code.substring(3,4).toLowerCase(); voice = code.substring(4,5).toLowerCase(); mood = code.substring(5,6).toLowerCase(); } if (voice.equals("e")) { voice = "p"; } else if ( (!(voice.equals("p"))) && (!(voice.equals("m"))) ) { String voice_displayed_as_active = "adnoqx"; if (voice_displayed_as_active.indexOf(voice) == -1) { LOGGER.warn("cannot identify morphology for [{}]", code); } voice = "a"; } classes = "v" + tense + voice + mood; if (classes == null) { LOGGER.warn("cannot identify morphology for [{}]", code); } } else { LOGGER.warn("other than verb [{}]", code); } } if (isBlank(classes) && firstSpace != -1) { return getColorClass(morph.substring(firstSpace + 1)); } } return classes != null ? classes : ""; } }
ColorCoderProviderImpl { public String getColorClass(final String morph) { if (morph == null || morph.length() < MINIMUM_MORPH_LENGTH) { return ""; } String classes = null; if (morph.startsWith(ROBINSON_PREFIX_LC) || morph.startsWith(ROBINSON_PREFIX_UC)) { LOGGER.debug("Identifying grammar for [{}]", morph); final int length = ROBINSON_PREFIX_LC.length(); final int firstSpace = morph.indexOf(' ', length); String code; if (firstSpace != -1) { code = morph.substring(length, firstSpace); } else { code = morph.substring(length); } final EntityDoc[] results = this.morphology.searchExactTermBySingleField("code", 1, code); if (results.length > 0) { classes = results[0].get("cssClasses"); String funct; try { funct = results[0].get("function").toLowerCase(); } catch (NullPointerException e) { funct = ""; } if (funct.equals("verb")) { String tense, voice, mood; try { tense = results[0].get("tense").toLowerCase(); voice = results[0].get("voice").toLowerCase(); mood = results[0].get("mood").toLowerCase(); } catch (NullPointerException e) { tense = voice = mood = ""; } if (!tense.isEmpty() && !mood.isEmpty()) { if (tense.startsWith("2nd ")) { tense = tense.substring(4); } else if (tense.equals("indefinite tense")) { tense = "indefinite"; } if ( (voice.equals("passive")) || (voice.equals("either middle or passive")) ) { voice = "p"; } else if (voice.equals("middle") ) { voice = "m"; } else if ((voice.indexOf("active") > -1) || (voice.indexOf("deponent") > -1) || (voice.indexOf("indefinite") > -1) ) { voice = "a"; } else { LOGGER.warn("cannot identify voice [{}]", voice); voice = "a"; } classes = classes + " v" + getShortCodeTense(tense) + voice + getShortCodeMood(mood); } } } else if (code.length() > 4) { if (code.substring(0,1).equalsIgnoreCase("v")) { String tense = code.substring(2,3).toLowerCase(); String voice = code.substring(3,4).toLowerCase(); String mood = code.substring(4,5).toLowerCase(); if (tense.equals("2")) { tense = code.substring(3,4).toLowerCase(); voice = code.substring(4,5).toLowerCase(); mood = code.substring(5,6).toLowerCase(); } if (voice.equals("e")) { voice = "p"; } else if ( (!(voice.equals("p"))) && (!(voice.equals("m"))) ) { String voice_displayed_as_active = "adnoqx"; if (voice_displayed_as_active.indexOf(voice) == -1) { LOGGER.warn("cannot identify morphology for [{}]", code); } voice = "a"; } classes = "v" + tense + voice + mood; if (classes == null) { LOGGER.warn("cannot identify morphology for [{}]", code); } } else { LOGGER.warn("other than verb [{}]", code); } } if (isBlank(classes) && firstSpace != -1) { return getColorClass(morph.substring(firstSpace + 1)); } } return classes != null ? classes : ""; } @Inject  ColorCoderProviderImpl(final EntityManager manager); }
ColorCoderProviderImpl { public String getColorClass(final String morph) { if (morph == null || morph.length() < MINIMUM_MORPH_LENGTH) { return ""; } String classes = null; if (morph.startsWith(ROBINSON_PREFIX_LC) || morph.startsWith(ROBINSON_PREFIX_UC)) { LOGGER.debug("Identifying grammar for [{}]", morph); final int length = ROBINSON_PREFIX_LC.length(); final int firstSpace = morph.indexOf(' ', length); String code; if (firstSpace != -1) { code = morph.substring(length, firstSpace); } else { code = morph.substring(length); } final EntityDoc[] results = this.morphology.searchExactTermBySingleField("code", 1, code); if (results.length > 0) { classes = results[0].get("cssClasses"); String funct; try { funct = results[0].get("function").toLowerCase(); } catch (NullPointerException e) { funct = ""; } if (funct.equals("verb")) { String tense, voice, mood; try { tense = results[0].get("tense").toLowerCase(); voice = results[0].get("voice").toLowerCase(); mood = results[0].get("mood").toLowerCase(); } catch (NullPointerException e) { tense = voice = mood = ""; } if (!tense.isEmpty() && !mood.isEmpty()) { if (tense.startsWith("2nd ")) { tense = tense.substring(4); } else if (tense.equals("indefinite tense")) { tense = "indefinite"; } if ( (voice.equals("passive")) || (voice.equals("either middle or passive")) ) { voice = "p"; } else if (voice.equals("middle") ) { voice = "m"; } else if ((voice.indexOf("active") > -1) || (voice.indexOf("deponent") > -1) || (voice.indexOf("indefinite") > -1) ) { voice = "a"; } else { LOGGER.warn("cannot identify voice [{}]", voice); voice = "a"; } classes = classes + " v" + getShortCodeTense(tense) + voice + getShortCodeMood(mood); } } } else if (code.length() > 4) { if (code.substring(0,1).equalsIgnoreCase("v")) { String tense = code.substring(2,3).toLowerCase(); String voice = code.substring(3,4).toLowerCase(); String mood = code.substring(4,5).toLowerCase(); if (tense.equals("2")) { tense = code.substring(3,4).toLowerCase(); voice = code.substring(4,5).toLowerCase(); mood = code.substring(5,6).toLowerCase(); } if (voice.equals("e")) { voice = "p"; } else if ( (!(voice.equals("p"))) && (!(voice.equals("m"))) ) { String voice_displayed_as_active = "adnoqx"; if (voice_displayed_as_active.indexOf(voice) == -1) { LOGGER.warn("cannot identify morphology for [{}]", code); } voice = "a"; } classes = "v" + tense + voice + mood; if (classes == null) { LOGGER.warn("cannot identify morphology for [{}]", code); } } else { LOGGER.warn("other than verb [{}]", code); } } if (isBlank(classes) && firstSpace != -1) { return getColorClass(morph.substring(firstSpace + 1)); } } return classes != null ? classes : ""; } @Inject  ColorCoderProviderImpl(final EntityManager manager); String getColorClass(final String morph); String getShortCodeTense(final String tense); String getShortCodeMood(final String mood); }
ColorCoderProviderImpl { public String getColorClass(final String morph) { if (morph == null || morph.length() < MINIMUM_MORPH_LENGTH) { return ""; } String classes = null; if (morph.startsWith(ROBINSON_PREFIX_LC) || morph.startsWith(ROBINSON_PREFIX_UC)) { LOGGER.debug("Identifying grammar for [{}]", morph); final int length = ROBINSON_PREFIX_LC.length(); final int firstSpace = morph.indexOf(' ', length); String code; if (firstSpace != -1) { code = morph.substring(length, firstSpace); } else { code = morph.substring(length); } final EntityDoc[] results = this.morphology.searchExactTermBySingleField("code", 1, code); if (results.length > 0) { classes = results[0].get("cssClasses"); String funct; try { funct = results[0].get("function").toLowerCase(); } catch (NullPointerException e) { funct = ""; } if (funct.equals("verb")) { String tense, voice, mood; try { tense = results[0].get("tense").toLowerCase(); voice = results[0].get("voice").toLowerCase(); mood = results[0].get("mood").toLowerCase(); } catch (NullPointerException e) { tense = voice = mood = ""; } if (!tense.isEmpty() && !mood.isEmpty()) { if (tense.startsWith("2nd ")) { tense = tense.substring(4); } else if (tense.equals("indefinite tense")) { tense = "indefinite"; } if ( (voice.equals("passive")) || (voice.equals("either middle or passive")) ) { voice = "p"; } else if (voice.equals("middle") ) { voice = "m"; } else if ((voice.indexOf("active") > -1) || (voice.indexOf("deponent") > -1) || (voice.indexOf("indefinite") > -1) ) { voice = "a"; } else { LOGGER.warn("cannot identify voice [{}]", voice); voice = "a"; } classes = classes + " v" + getShortCodeTense(tense) + voice + getShortCodeMood(mood); } } } else if (code.length() > 4) { if (code.substring(0,1).equalsIgnoreCase("v")) { String tense = code.substring(2,3).toLowerCase(); String voice = code.substring(3,4).toLowerCase(); String mood = code.substring(4,5).toLowerCase(); if (tense.equals("2")) { tense = code.substring(3,4).toLowerCase(); voice = code.substring(4,5).toLowerCase(); mood = code.substring(5,6).toLowerCase(); } if (voice.equals("e")) { voice = "p"; } else if ( (!(voice.equals("p"))) && (!(voice.equals("m"))) ) { String voice_displayed_as_active = "adnoqx"; if (voice_displayed_as_active.indexOf(voice) == -1) { LOGGER.warn("cannot identify morphology for [{}]", code); } voice = "a"; } classes = "v" + tense + voice + mood; if (classes == null) { LOGGER.warn("cannot identify morphology for [{}]", code); } } else { LOGGER.warn("other than verb [{}]", code); } } if (isBlank(classes) && firstSpace != -1) { return getColorClass(morph.substring(firstSpace + 1)); } } return classes != null ? classes : ""; } @Inject  ColorCoderProviderImpl(final EntityManager manager); String getColorClass(final String morph); String getShortCodeTense(final String tense); String getShortCodeMood(final String mood);  }