@Test public void testSubtractiveBiochemicalPreferredToRightMost() throws ComponentGenerationException{ Element word = new GroupingEl(WORD_EL); Element substituent = new GroupingEl(SUBSTITUENT_EL); Element substractivePrefix = new TokenEl(SUBTRACTIVEPREFIX_EL); substractivePrefix.addAttribute(new Attribute(TYPE_ATR, DEOXY_TYPE_VAL)); substituent.addChild(substractivePrefix); word.addChild(substituent); Element substituent2 = new GroupingEl(SUBSTITUENT_EL); Element group1 = new TokenEl(GROUP_EL); group1.addAttribute(new Attribute(SUBTYPE_ATR, BIOCHEMICAL_SUBTYPE_VAL)); substituent2.addChild(group1); word.addChild(substituent2); Element root = new GroupingEl(ROOT_EL); word.addChild(root); Element group2 = new TokenEl(GROUP_EL); group2.addAttribute(new Attribute(SUBTYPE_ATR, SIMPLEGROUP_SUBTYPE_VAL)); root.addChild(group2); ComponentProcessor.removeAndMoveToAppropriateGroupIfSubtractivePrefix(substituent); assertEquals("Substractive prefix should of been detached", null, substituent.getParent()); assertEquals(1, root.getChildCount()); assertEquals(2, substituent2.getChildCount()); assertEquals(substractivePrefix, substituent2.getChildElements().get(0)); }
static boolean removeAndMoveToAppropriateGroupIfSubtractivePrefix(Element substituent) throws ComponentGenerationException { List<Element> subtractivePrefixes = substituent.getChildElements(SUBTRACTIVEPREFIX_EL); if (subtractivePrefixes.size() > 0) { Element biochemicalGroup = null; Element standardGroup = null; final Element adjacentSubOrRootOrBracket = OpsinTools.getNextSibling(substituent); Element nextSubOrRootOrBracket = adjacentSubOrRootOrBracket; if (nextSubOrRootOrBracket == null){ throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } while (nextSubOrRootOrBracket != null) { Element groupToConsider = nextSubOrRootOrBracket.getFirstChildElement(GROUP_EL); if (groupToConsider != null) { if (OpsinTools.isBiochemical(groupToConsider.getAttributeValue(TYPE_ATR), groupToConsider.getAttributeValue(SUBTYPE_ATR))){ biochemicalGroup = groupToConsider; if (OpsinTools.getPreviousSiblingsOfType(biochemicalGroup, LOCANT_EL).size() == 0) { break; } } else { standardGroup = groupToConsider; } } nextSubOrRootOrBracket = OpsinTools.getNextSibling(nextSubOrRootOrBracket); } Element targetGroup = biochemicalGroup != null ? biochemicalGroup : standardGroup; if (targetGroup == null) { throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } List<Element> children = substituent.getChildElements(); Element targetSubstituent = targetGroup.getParent(); if (targetSubstituent.equals(adjacentSubOrRootOrBracket)) { for (int i = children.size()-1; i >=0 ; i--) { Element child =children.get(i); if (!child.getName().equals(HYPHEN_EL)){ child.detach(); targetSubstituent.insertChild(child, 0); } } } else { boolean inDetachablePrefix = true; for (int i = children.size()-1; i >=0 ; i--) { Element child = children.get(i); String elName = child.getName(); if (elName.equals(HYPHEN_EL)) { continue; } else if (inDetachablePrefix && elName.equals(SUBTRACTIVEPREFIX_EL)) { child.detach(); targetSubstituent.insertChild(child, 0); } else if (elName.equals(STEREOCHEMISTRY_EL)) { inDetachablePrefix = false; child.detach(); adjacentSubOrRootOrBracket.insertChild(child, 0); } else { throw new ComponentGenerationException("Unexpected term found before detachable substractive prefix: " + child.getValue() ); } } } substituent.detach(); return true; } return false; }
ComponentProcessor { static boolean removeAndMoveToAppropriateGroupIfSubtractivePrefix(Element substituent) throws ComponentGenerationException { List<Element> subtractivePrefixes = substituent.getChildElements(SUBTRACTIVEPREFIX_EL); if (subtractivePrefixes.size() > 0) { Element biochemicalGroup = null; Element standardGroup = null; final Element adjacentSubOrRootOrBracket = OpsinTools.getNextSibling(substituent); Element nextSubOrRootOrBracket = adjacentSubOrRootOrBracket; if (nextSubOrRootOrBracket == null){ throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } while (nextSubOrRootOrBracket != null) { Element groupToConsider = nextSubOrRootOrBracket.getFirstChildElement(GROUP_EL); if (groupToConsider != null) { if (OpsinTools.isBiochemical(groupToConsider.getAttributeValue(TYPE_ATR), groupToConsider.getAttributeValue(SUBTYPE_ATR))){ biochemicalGroup = groupToConsider; if (OpsinTools.getPreviousSiblingsOfType(biochemicalGroup, LOCANT_EL).size() == 0) { break; } } else { standardGroup = groupToConsider; } } nextSubOrRootOrBracket = OpsinTools.getNextSibling(nextSubOrRootOrBracket); } Element targetGroup = biochemicalGroup != null ? biochemicalGroup : standardGroup; if (targetGroup == null) { throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } List<Element> children = substituent.getChildElements(); Element targetSubstituent = targetGroup.getParent(); if (targetSubstituent.equals(adjacentSubOrRootOrBracket)) { for (int i = children.size()-1; i >=0 ; i--) { Element child =children.get(i); if (!child.getName().equals(HYPHEN_EL)){ child.detach(); targetSubstituent.insertChild(child, 0); } } } else { boolean inDetachablePrefix = true; for (int i = children.size()-1; i >=0 ; i--) { Element child = children.get(i); String elName = child.getName(); if (elName.equals(HYPHEN_EL)) { continue; } else if (inDetachablePrefix && elName.equals(SUBTRACTIVEPREFIX_EL)) { child.detach(); targetSubstituent.insertChild(child, 0); } else if (elName.equals(STEREOCHEMISTRY_EL)) { inDetachablePrefix = false; child.detach(); adjacentSubOrRootOrBracket.insertChild(child, 0); } else { throw new ComponentGenerationException("Unexpected term found before detachable substractive prefix: " + child.getValue() ); } } } substituent.detach(); return true; } return false; } }
ComponentProcessor { static boolean removeAndMoveToAppropriateGroupIfSubtractivePrefix(Element substituent) throws ComponentGenerationException { List<Element> subtractivePrefixes = substituent.getChildElements(SUBTRACTIVEPREFIX_EL); if (subtractivePrefixes.size() > 0) { Element biochemicalGroup = null; Element standardGroup = null; final Element adjacentSubOrRootOrBracket = OpsinTools.getNextSibling(substituent); Element nextSubOrRootOrBracket = adjacentSubOrRootOrBracket; if (nextSubOrRootOrBracket == null){ throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } while (nextSubOrRootOrBracket != null) { Element groupToConsider = nextSubOrRootOrBracket.getFirstChildElement(GROUP_EL); if (groupToConsider != null) { if (OpsinTools.isBiochemical(groupToConsider.getAttributeValue(TYPE_ATR), groupToConsider.getAttributeValue(SUBTYPE_ATR))){ biochemicalGroup = groupToConsider; if (OpsinTools.getPreviousSiblingsOfType(biochemicalGroup, LOCANT_EL).size() == 0) { break; } } else { standardGroup = groupToConsider; } } nextSubOrRootOrBracket = OpsinTools.getNextSibling(nextSubOrRootOrBracket); } Element targetGroup = biochemicalGroup != null ? biochemicalGroup : standardGroup; if (targetGroup == null) { throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } List<Element> children = substituent.getChildElements(); Element targetSubstituent = targetGroup.getParent(); if (targetSubstituent.equals(adjacentSubOrRootOrBracket)) { for (int i = children.size()-1; i >=0 ; i--) { Element child =children.get(i); if (!child.getName().equals(HYPHEN_EL)){ child.detach(); targetSubstituent.insertChild(child, 0); } } } else { boolean inDetachablePrefix = true; for (int i = children.size()-1; i >=0 ; i--) { Element child = children.get(i); String elName = child.getName(); if (elName.equals(HYPHEN_EL)) { continue; } else if (inDetachablePrefix && elName.equals(SUBTRACTIVEPREFIX_EL)) { child.detach(); targetSubstituent.insertChild(child, 0); } else if (elName.equals(STEREOCHEMISTRY_EL)) { inDetachablePrefix = false; child.detach(); adjacentSubOrRootOrBracket.insertChild(child, 0); } else { throw new ComponentGenerationException("Unexpected term found before detachable substractive prefix: " + child.getValue() ); } } } substituent.detach(); return true; } return false; } ComponentProcessor(BuildState state, SuffixApplier suffixApplier); }
ComponentProcessor { static boolean removeAndMoveToAppropriateGroupIfSubtractivePrefix(Element substituent) throws ComponentGenerationException { List<Element> subtractivePrefixes = substituent.getChildElements(SUBTRACTIVEPREFIX_EL); if (subtractivePrefixes.size() > 0) { Element biochemicalGroup = null; Element standardGroup = null; final Element adjacentSubOrRootOrBracket = OpsinTools.getNextSibling(substituent); Element nextSubOrRootOrBracket = adjacentSubOrRootOrBracket; if (nextSubOrRootOrBracket == null){ throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } while (nextSubOrRootOrBracket != null) { Element groupToConsider = nextSubOrRootOrBracket.getFirstChildElement(GROUP_EL); if (groupToConsider != null) { if (OpsinTools.isBiochemical(groupToConsider.getAttributeValue(TYPE_ATR), groupToConsider.getAttributeValue(SUBTYPE_ATR))){ biochemicalGroup = groupToConsider; if (OpsinTools.getPreviousSiblingsOfType(biochemicalGroup, LOCANT_EL).size() == 0) { break; } } else { standardGroup = groupToConsider; } } nextSubOrRootOrBracket = OpsinTools.getNextSibling(nextSubOrRootOrBracket); } Element targetGroup = biochemicalGroup != null ? biochemicalGroup : standardGroup; if (targetGroup == null) { throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } List<Element> children = substituent.getChildElements(); Element targetSubstituent = targetGroup.getParent(); if (targetSubstituent.equals(adjacentSubOrRootOrBracket)) { for (int i = children.size()-1; i >=0 ; i--) { Element child =children.get(i); if (!child.getName().equals(HYPHEN_EL)){ child.detach(); targetSubstituent.insertChild(child, 0); } } } else { boolean inDetachablePrefix = true; for (int i = children.size()-1; i >=0 ; i--) { Element child = children.get(i); String elName = child.getName(); if (elName.equals(HYPHEN_EL)) { continue; } else if (inDetachablePrefix && elName.equals(SUBTRACTIVEPREFIX_EL)) { child.detach(); targetSubstituent.insertChild(child, 0); } else if (elName.equals(STEREOCHEMISTRY_EL)) { inDetachablePrefix = false; child.detach(); adjacentSubOrRootOrBracket.insertChild(child, 0); } else { throw new ComponentGenerationException("Unexpected term found before detachable substractive prefix: " + child.getValue() ); } } } substituent.detach(); return true; } return false; } ComponentProcessor(BuildState state, SuffixApplier suffixApplier);  }
ComponentProcessor { static boolean removeAndMoveToAppropriateGroupIfSubtractivePrefix(Element substituent) throws ComponentGenerationException { List<Element> subtractivePrefixes = substituent.getChildElements(SUBTRACTIVEPREFIX_EL); if (subtractivePrefixes.size() > 0) { Element biochemicalGroup = null; Element standardGroup = null; final Element adjacentSubOrRootOrBracket = OpsinTools.getNextSibling(substituent); Element nextSubOrRootOrBracket = adjacentSubOrRootOrBracket; if (nextSubOrRootOrBracket == null){ throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } while (nextSubOrRootOrBracket != null) { Element groupToConsider = nextSubOrRootOrBracket.getFirstChildElement(GROUP_EL); if (groupToConsider != null) { if (OpsinTools.isBiochemical(groupToConsider.getAttributeValue(TYPE_ATR), groupToConsider.getAttributeValue(SUBTYPE_ATR))){ biochemicalGroup = groupToConsider; if (OpsinTools.getPreviousSiblingsOfType(biochemicalGroup, LOCANT_EL).size() == 0) { break; } } else { standardGroup = groupToConsider; } } nextSubOrRootOrBracket = OpsinTools.getNextSibling(nextSubOrRootOrBracket); } Element targetGroup = biochemicalGroup != null ? biochemicalGroup : standardGroup; if (targetGroup == null) { throw new ComponentGenerationException("Unable to find group for: " + subtractivePrefixes.get(0).getValue() +" to apply to!"); } List<Element> children = substituent.getChildElements(); Element targetSubstituent = targetGroup.getParent(); if (targetSubstituent.equals(adjacentSubOrRootOrBracket)) { for (int i = children.size()-1; i >=0 ; i--) { Element child =children.get(i); if (!child.getName().equals(HYPHEN_EL)){ child.detach(); targetSubstituent.insertChild(child, 0); } } } else { boolean inDetachablePrefix = true; for (int i = children.size()-1; i >=0 ; i--) { Element child = children.get(i); String elName = child.getName(); if (elName.equals(HYPHEN_EL)) { continue; } else if (inDetachablePrefix && elName.equals(SUBTRACTIVEPREFIX_EL)) { child.detach(); targetSubstituent.insertChild(child, 0); } else if (elName.equals(STEREOCHEMISTRY_EL)) { inDetachablePrefix = false; child.detach(); adjacentSubOrRootOrBracket.insertChild(child, 0); } else { throw new ComponentGenerationException("Unexpected term found before detachable substractive prefix: " + child.getValue() ); } } } substituent.detach(); return true; } return false; } ComponentProcessor(BuildState state, SuffixApplier suffixApplier);   }