Finds the index of appearance of a term's sub-term.


@param subTerm
the inner term, must be included in <code>term</code>
@param term
the container term.
@return
the starting index of <code>subTerm</code> in <code>term</code>. -1 otherwise.
167679
public static int getPosition(Term subTerm, Term term) {
		int startingIndex = -1;
		int j = 0;
		for(int i=0; i<term.getWords().size(); i++) {
			if(term.getWords().get(i).equals(subTerm.getWords().get(j))) {
				j++;
				if(startingIndex == -1) 
					startingIndex = i;
			} else {
				startingIndex = -1;
				j = 0;
			}
			if(j == subTerm.getWords().size())
				return startingIndex;
		}
		return -1;
	}
1154232
private List<WComponent> getComponentsForTerm(final String term) {
		List<WComponent> childList = content.getComponentModel().getChildren();
		List<WComponent> result = new ArrayList<>();

		if (childList != null) {
			for (int i = 0; i < childList.size(); i++) {
				WComponent child = childList.get(i);

				if (term.equals(child.getTag())) {
					result.add(child);
				}
			}
		}

		return result;
	}
1333912
private void outputIndexTerm(final IndexTerm term, final XMLStreamWriter serializer, final boolean indexsee) throws XMLStreamException {
        final List<IndexTerm> subTerms = term.getSubTerms();
        final int subTermNum = subTerms.size();
        outputIndexTermStartElement(term, serializer, indexsee);
        if (subTermNum > 0) {
            for (final IndexTerm subTerm : subTerms) {
                outputIndexTerm(subTerm, serializer, indexsee);
            }
        }
        outputIndexTermEndElement(term, serializer, indexsee);
    }
535299
private void findTargets(final IndexTerm term) {
        final List<IndexTerm> subTerms = term.getSubTerms();
        List<IndexTermTarget> subTargets = null;
        if (subTerms != null && ! subTerms.isEmpty()){
            for (final IndexTerm subTerm : subTerms) {
                subTargets = subTerm.getTargetList();
                if (subTargets != null && !subTargets.isEmpty()) {
                    //findTargets(subTerm);
                    //add targets(child term)
                    term.addTargets(subTerm.getTargetList());
                } else {
                    //term.addTargets(subTerm.getTargetList());
                    //recursive search child's child term
                    findTargets(subTerm);
                }
                //add target to parent indexterm
                term.addTargets(subTerm.getTargetList());
            }

        }
    }
1020087
@Override
    public void recognition(Term[] terms) {
        int length = terms.length - 1;
        Term from = null;
        Term to = null;
        Term temp = null;
        for (int i = 0; i < length; i++) {
            if (terms[i] == null) {
                continue;
            } else if (".".equals(terms[i].getName()) || "．".equals(terms[i].getName())) {
                // 如果是.前后都为数字进行特殊处理
                to = terms[i].to();
                from = terms[i].from();
                if (from.termNatures().numAttr.flag && to.termNatures().numAttr.flag) {
                    from.setName(from.getName() + "." + to.getName());
                    TermUtil.termLink(from, to.to());
                    terms[to.getOffe()] = null;
                    terms[i] = null;
                    i = from.getOffe() - 1;
                }
                continue;
            } else if (!terms[i].termNatures().numAttr.flag) {
                continue;
            }

            temp = terms[i];
            // 将所有的数字合并
            while ((temp = temp.to()).termNatures().numAttr.flag) {
                terms[i].setName(terms[i].getName() + temp.getName());
            }
            // 如果是数字结尾
            if (MyStaticValue.isQuantifierRecognition && temp.termNatures().numAttr.numEndFreq > 0) {
                terms[i].setName(terms[i].getName() + temp.getName());
                temp = temp.to();
            }

            // 如果不等,说明terms[i]发生了改变
            if (terms[i].to() != temp) {
                TermUtil.termLink(terms[i], temp);
                // 将中间无用元素设置为null
                for (int j = i + 1; j < temp.getOffe(); j++) {
                    terms[j] = null;
                }
                i = temp.getOffe() - 1;
            }
        }

    }
952497
private void outputIndexTerm(final IndexTerm term, final XMLSerializer serializer) throws SAXException {
        List<IndexTermTarget> targets = term.getTargetList();
        final List<IndexTerm> subTerms = term.getSubTerms();
        int targetNum = targets.size();
        final int subTermNum = subTerms.size();

        serializer.writeStartElement("li");
        serializer.writeStartElement("object");
        serializer.writeAttribute("type", "text/sitemap");
        serializer.writeStartElement("param");
        serializer.writeAttribute("name", "Name");
        serializer.writeAttribute("value", term.getTermFullName());
        serializer.writeEndElement(); // param
        //if term doesn't has target to link to, it won't appear in the index tab
        //we need to create links for such terms
        if (targets.isEmpty()){
            findTargets(term);
            targets = term.getTargetList();
            targetNum = targets.size();
        }
        for (int i = 0; i < targetNum; i++) {
            final IndexTermTarget target = targets.get(i);
            serializer.writeStartElement("param");
            serializer.writeAttribute("name", "Name");
            serializer.writeAttribute("value", target.getTargetName());
            serializer.writeEndElement(); // param
            serializer.writeStartElement("param");
            serializer.writeAttribute("name", "Local");
            serializer.writeAttribute("value", target.getTargetURI());
            serializer.writeEndElement(); // param
        }
        serializer.writeEndElement(); // object
        if (subTermNum > 0) {
            serializer.writeStartElement("ul");
            for (final IndexTerm subTerm : subTerms) {
                outputIndexTerm(subTerm, serializer);
            }
            serializer.writeEndElement(); // ul
        }
        serializer.writeEndElement(); // li
    }
997878
@Override
    public void addWordToIndex(int index, String label) {
        if (index >= 0) {
            T token = tokenFor(label);
            if (token != null) {
                idxMap.put(index, token);
                token.setIndex(index);
            }
        }
    }
1346081
public void removeTerm(final String term) {
		for (WComponent child : getComponentsForTerm(term)) {
			content.remove(child);
		}
	}
1203672
public static Expression position(Expression expression, String substring) {
        return x("POSITION(" + expression.toString() + ", \"" + substring + "\")");
    }
839379
public static Pattern findSubstructure(IAtomContainer query) {
        boolean isQuery = query instanceof IQueryAtomContainer;
        return findSubstructure(query,
                                isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(),
                                isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder());
    }
1200816
@Override
    public boolean containsTerm(Term t) {
        List<Term> terms = getTerms();
        for (int i = 0; i < terms.size(); i++) {
            Term t2 = terms.get(i);
            if (t2.equals(t))
                return true;
        }
        return false;
    }
289875
private boolean isMinuteTerm(final int currentTermIdx, final List<Term<Calendar>> terms) {
        
        final int termSize = terms.size();
        
        // 直前の項のチェック
        if(currentTermIdx -1 > 0) {
            DateTerm beforeTerm = null;
            for(int i=currentTermIdx-1; i >= 0; i--) {
                final Term<Calendar> term = terms.get(i);
                if(term instanceof DateTerm) {
                    beforeTerm = (DateTerm) term;
                    break;
                }
                
            }
            
            if(beforeTerm != null) {
                if(beforeTerm instanceof DateTerm.HourTerm || beforeTerm instanceof DateTerm.ElapsedHourTerm) {
                    return true;
                }
            }
            
        }
        
        // 直後の項のチェック
        if(currentTermIdx +1 < termSize) {
            DateTerm afterTerm = null;
            for(int i=currentTermIdx+1; i < termSize; i++) {
                final Term<Calendar> term = terms.get(i);
                if(term instanceof DateTerm) {
                    afterTerm = (DateTerm) term;
                    break;
                }
            }
            
            if(afterTerm != null) {
                if(afterTerm instanceof DateTerm.SecondTerm || afterTerm instanceof DateTerm.ElapsedSecondTerm) {
                    return true;
                }
            }
        }
        
        return false;
    }
515225
private SmartForest<String[]> termStatus(SmartForest<String[]> branch, Term term) {
        String name = term.getName();
        SmartForest<String[]> sf = branch;
        for (int j = 0; j < name.length(); j++) {
            sf = sf.get(name.charAt(j));
            if (sf == null) {
                return null;
            }
        }
        return sf;
    }
1133009
def subclass(cls, t):
        """"""
        t.doc = None
        t.terms = []
        t.__class__ = SectionTerm
        return t
1135702
public int getDepth(int index) {
    if (index == 0) {
      return 0;
    } else {
      int[] parts = findSubexpression(index);
      return 1 + subexpressions.get(parts[0]).getDepth(parts[1]);
    }
  }
427527
def get_document_frequency(self, term):
        
        if term not in self._terms:
            raise IndexError(TERM_DOES_NOT_EXIST)
        else:
            return len(self._terms[term])
779574
public int getParentExpressionIndex(int index) {
    if (index == 0) {
      return -1;
    } else {
      int[] parts = findSubexpression(index);
      int parentIndex = subexpressions.get(parts[0]).getParentExpressionIndex(parts[1]);
      
      if (parentIndex == -1) {
        // index refers to a child of this expression.
        return 0;
      } else {
        // Return the index into this expression of the chosen child,
        // plus the index into that expression.
        return parentIndex + parts[2]; 
      }
    }
  }