@Test public void testSetStructireInfo() { Reader reader = new StringReader("C2H5OH"); SemiStructureTokenizer tokenizer = new SemiStructureTokenizer(reader); assertTrue(tokenizer.fragmentsCounts.containsKey("C")); assertTrue(tokenizer.fragmentsCounts.containsKey("C-C")); assertTrue(tokenizer.fragmentsCounts.containsKey("O")); assertEquals(tokenizer.fragmentsCounts.size(),3); }
private void setStructireInfo(Reader input) { SemistructuredFormulaParser formulaParser = new SemistructuredFormulaParser(input); try { ChemSubStructure structure = formulaParser.parse(); Stack<DFSStackEntry> stack = new Stack<DFSStackEntry>(); stack.push(new DFSStackEntry(structure,1)); while (!stack.isEmpty()) { DFSStackEntry currentEntry = stack.pop(); ChemSubStructure current = currentEntry.subStructure; int multiplier = currentEntry.multiplier; if (current instanceof Element) { mapFragmentsChains(((Element) current).subFormula, multiplier); } else if (current instanceof ElementaryGroup) { mapFragmentsChains(((ElementaryGroup) current).subFormula, multiplier); } else if (current instanceof Group) { ChemSubStructure containedSubStructure = ((Group)current).containedSubStructure; stack.push(new DFSStackEntry(containedSubStructure, multiplier)); } else if (current instanceof Term) { Term asTerm = ((Term)current); stack.push(new DFSStackEntry(asTerm.subStrucure, multiplier * asTerm.multiplier)); } else if (current instanceof Formula) { for (ChemSubStructure subStructure : ((Formula) current).subStructures) { stack.push(new DFSStackEntry(subStructure, multiplier) ); } } } currentIterator = fragmentsCounts.entrySet().iterator(); currentCount = 0; } catch (ParseException e) { throw new RuntimeException(e); } }
SemiStructureTokenizer extends Tokenizer { private void setStructireInfo(Reader input) { SemistructuredFormulaParser formulaParser = new SemistructuredFormulaParser(input); try { ChemSubStructure structure = formulaParser.parse(); Stack<DFSStackEntry> stack = new Stack<DFSStackEntry>(); stack.push(new DFSStackEntry(structure,1)); while (!stack.isEmpty()) { DFSStackEntry currentEntry = stack.pop(); ChemSubStructure current = currentEntry.subStructure; int multiplier = currentEntry.multiplier; if (current instanceof Element) { mapFragmentsChains(((Element) current).subFormula, multiplier); } else if (current instanceof ElementaryGroup) { mapFragmentsChains(((ElementaryGroup) current).subFormula, multiplier); } else if (current instanceof Group) { ChemSubStructure containedSubStructure = ((Group)current).containedSubStructure; stack.push(new DFSStackEntry(containedSubStructure, multiplier)); } else if (current instanceof Term) { Term asTerm = ((Term)current); stack.push(new DFSStackEntry(asTerm.subStrucure, multiplier * asTerm.multiplier)); } else if (current instanceof Formula) { for (ChemSubStructure subStructure : ((Formula) current).subStructures) { stack.push(new DFSStackEntry(subStructure, multiplier) ); } } } currentIterator = fragmentsCounts.entrySet().iterator(); currentCount = 0; } catch (ParseException e) { throw new RuntimeException(e); } } }
SemiStructureTokenizer extends Tokenizer { private void setStructireInfo(Reader input) { SemistructuredFormulaParser formulaParser = new SemistructuredFormulaParser(input); try { ChemSubStructure structure = formulaParser.parse(); Stack<DFSStackEntry> stack = new Stack<DFSStackEntry>(); stack.push(new DFSStackEntry(structure,1)); while (!stack.isEmpty()) { DFSStackEntry currentEntry = stack.pop(); ChemSubStructure current = currentEntry.subStructure; int multiplier = currentEntry.multiplier; if (current instanceof Element) { mapFragmentsChains(((Element) current).subFormula, multiplier); } else if (current instanceof ElementaryGroup) { mapFragmentsChains(((ElementaryGroup) current).subFormula, multiplier); } else if (current instanceof Group) { ChemSubStructure containedSubStructure = ((Group)current).containedSubStructure; stack.push(new DFSStackEntry(containedSubStructure, multiplier)); } else if (current instanceof Term) { Term asTerm = ((Term)current); stack.push(new DFSStackEntry(asTerm.subStrucure, multiplier * asTerm.multiplier)); } else if (current instanceof Formula) { for (ChemSubStructure subStructure : ((Formula) current).subStructures) { stack.push(new DFSStackEntry(subStructure, multiplier) ); } } } currentIterator = fragmentsCounts.entrySet().iterator(); currentCount = 0; } catch (ParseException e) { throw new RuntimeException(e); } } protected  SemiStructureTokenizer(Reader input); protected  SemiStructureTokenizer(AttributeFactory factory, Reader input); }
SemiStructureTokenizer extends Tokenizer { private void setStructireInfo(Reader input) { SemistructuredFormulaParser formulaParser = new SemistructuredFormulaParser(input); try { ChemSubStructure structure = formulaParser.parse(); Stack<DFSStackEntry> stack = new Stack<DFSStackEntry>(); stack.push(new DFSStackEntry(structure,1)); while (!stack.isEmpty()) { DFSStackEntry currentEntry = stack.pop(); ChemSubStructure current = currentEntry.subStructure; int multiplier = currentEntry.multiplier; if (current instanceof Element) { mapFragmentsChains(((Element) current).subFormula, multiplier); } else if (current instanceof ElementaryGroup) { mapFragmentsChains(((ElementaryGroup) current).subFormula, multiplier); } else if (current instanceof Group) { ChemSubStructure containedSubStructure = ((Group)current).containedSubStructure; stack.push(new DFSStackEntry(containedSubStructure, multiplier)); } else if (current instanceof Term) { Term asTerm = ((Term)current); stack.push(new DFSStackEntry(asTerm.subStrucure, multiplier * asTerm.multiplier)); } else if (current instanceof Formula) { for (ChemSubStructure subStructure : ((Formula) current).subStructures) { stack.push(new DFSStackEntry(subStructure, multiplier) ); } } } currentIterator = fragmentsCounts.entrySet().iterator(); currentCount = 0; } catch (ParseException e) { throw new RuntimeException(e); } } protected  SemiStructureTokenizer(Reader input); protected  SemiStructureTokenizer(AttributeFactory factory, Reader input); @Override final boolean incrementToken(); }
SemiStructureTokenizer extends Tokenizer { private void setStructireInfo(Reader input) { SemistructuredFormulaParser formulaParser = new SemistructuredFormulaParser(input); try { ChemSubStructure structure = formulaParser.parse(); Stack<DFSStackEntry> stack = new Stack<DFSStackEntry>(); stack.push(new DFSStackEntry(structure,1)); while (!stack.isEmpty()) { DFSStackEntry currentEntry = stack.pop(); ChemSubStructure current = currentEntry.subStructure; int multiplier = currentEntry.multiplier; if (current instanceof Element) { mapFragmentsChains(((Element) current).subFormula, multiplier); } else if (current instanceof ElementaryGroup) { mapFragmentsChains(((ElementaryGroup) current).subFormula, multiplier); } else if (current instanceof Group) { ChemSubStructure containedSubStructure = ((Group)current).containedSubStructure; stack.push(new DFSStackEntry(containedSubStructure, multiplier)); } else if (current instanceof Term) { Term asTerm = ((Term)current); stack.push(new DFSStackEntry(asTerm.subStrucure, multiplier * asTerm.multiplier)); } else if (current instanceof Formula) { for (ChemSubStructure subStructure : ((Formula) current).subStructures) { stack.push(new DFSStackEntry(subStructure, multiplier) ); } } } currentIterator = fragmentsCounts.entrySet().iterator(); currentCount = 0; } catch (ParseException e) { throw new RuntimeException(e); } } protected  SemiStructureTokenizer(Reader input); protected  SemiStructureTokenizer(AttributeFactory factory, Reader input); @Override final boolean incrementToken();  }