📄 elansearchengine.java
字号:
* @return Vector */ private static List getDescAnnotations(Annotation ancestorAnnotation, TierImpl[] relationship) { List childAnnotations = new ArrayList(); List parentAnnotations = new ArrayList(); parentAnnotations.add(ancestorAnnotation); for (int r = relationship.length - 1; r >= 0; r--) { childAnnotations = new ArrayList(); try { for (int i = 0; i < parentAnnotations.size(); i++) { childAnnotations.addAll(((Annotation) parentAnnotations.get( i)).getChildrenOnTier(relationship[r])); } } catch (Exception re) { re.printStackTrace(); return new ArrayList(); } parentAnnotations = childAnnotations; } return parentAnnotations; } /** * get all (pattern) matches in a tier * * @param parentMatch DOCUMENT ME! * @param pattern * @param constraintId DOCUMENT ME! * @param annotationList * @param range subindices * * @return int[] */ private static List getMatches(ElanMatch parentMatch, Pattern pattern, String constraintId, List annotationList, int[] range) { List matchList = new ArrayList(); for (int i = 0; i < range.length; i++) { Annotation annotation = (Annotation) annotationList.get(range[i]); Matcher matcher = pattern.matcher(annotation.getValue()); if (matcher.find()) { List substringIndices = new ArrayList(); do { substringIndices.add(new int[] { matcher.start(0), matcher.end(0) }); } while (matcher.find()); ElanMatch match = new ElanMatch(parentMatch, annotation, constraintId, range[i], (int[][]) substringIndices.toArray(new int[0][0])); if (range[i] > 0) { match.setLeftContext(((Annotation) annotationList.get(range[i] - 1)).getValue()); } if ((match.getIndex() + 1) < annotationList.size()) { match.setRightContext(((Annotation) annotationList.get(range[i] + 1)).getValue()); } matchList.add(match); } } return matchList; } /** * computes intersection of range and [0..tier.size] returns array of the * integers in this intersection * * @param tier * @param lowerBoundary * @param upperBoundary * @param center * * @return int[] */ private static int[] getRangeForTier(TierImpl tier, long lowerBoundary, long upperBoundary, int center) { int newLowerBoundary = (lowerBoundary == Long.MIN_VALUE) ? 0 : (int) Math.max(0, center + lowerBoundary); int newUpperBoundary = (upperBoundary == Long.MAX_VALUE) ? (tier.getNumberOfAnnotations() - 1) : (int) Math.min(tier.getNumberOfAnnotations() - 1, center + upperBoundary); int[] range = new int[-newLowerBoundary + newUpperBoundary + 1]; for (int i = 0; i < range.length; i++) { range[i] = i + newLowerBoundary; } return range; } /** * returns array of all Tiers between ancester and descendant tier, * including descendTier, excluding ancestorTier; empty, if ancestorTier * == descendTier * * @param ancesterTier * @param descendTier * * @return TierImpl[] */ private static TierImpl[] getRelationship(TierImpl ancesterTier, TierImpl descendTier) { List relationship = new ArrayList(); TierImpl parentTier = descendTier; try { if (descendTier.hasAncestor(ancesterTier)) { while (!ancesterTier.equals(parentTier)) { relationship.add(parentTier); parentTier = (TierImpl) parentTier.getParentTier(); } } } catch (Exception e) { e.printStackTrace(); } return (TierImpl[]) relationship.toArray(new TierImpl[0]); } /** * DOCUMENT ME! * * @param match * @param constraint * * @return DOCUMENT ME! * * @throws NullPointerException DOCUMENT ME! */ private List getChildMatches(ElanMatch match, Constraint constraint) throws NullPointerException { TierImpl unitTier = null; List unitAnnotations = null; List constraintAnnotations = null; TierImpl[] relShip = null; long lowerBoundary = constraint.getLowerBoundary(); long upperBoundary = constraint.getUpperBoundary(); Pattern pattern = (Pattern) patternHash.get(constraint); constraintAnnotations = (List) annotationHash.get(constraint.getTierName()); if (Constraint.STRUCTURAL.equals(constraint.getMode())) { unitTier = (TierImpl) unitTierHash.get(constraint); unitAnnotations = (List) annotationHash.get(unitTier.getName()); relShip = (TierImpl[]) relationshipHash.get(constraint); } List annotationsInScope; int[] annotationIndicesInScope; Annotation annotation = match.getAnnotation(); if (Constraint.TEMPORAL.equals(constraint.getMode())) { annotationIndicesInScope = getAnnotationIndicesInScope(constraintAnnotations, annotation.getBeginTimeBoundary(), annotation.getEndTimeBoundary(), upperBoundary, constraint.getUnit()); } else { annotationsInScope = getAnnotationsInScope(lowerBoundary, upperBoundary, unitTier, unitAnnotations, relShip, annotation); annotationIndicesInScope = new int[annotationsInScope.size()]; for (int j = 0; j < annotationsInScope.size(); j++) { annotationIndicesInScope[j] = constraintAnnotations.indexOf(annotationsInScope.get( j)); logger.log(Level.FINE, "Constraint annotation: " + ((Annotation) annotationsInScope.get(j)).getValue()); } } List matches = getMatches(match, pattern, constraint.getId(), constraintAnnotations, annotationIndicesInScope); filterDependentConstraints(matches, constraint); return matches; } private void fillAnnotationHash(Constraint constraint) throws QueryFormulationException { String[] tierNames = constraint.getTierNames(); TierImpl[] tiers; if (tierNames[0].equals(Constraint.ALL_TIERS)) { tiers = (TierImpl[]) transcription.getTiers().toArray(new TierImpl[0]); } else { tiers = new TierImpl[tierNames.length]; for (int i = 0; i < tierNames.length; i++) { tiers[i] = (TierImpl) transcription.getTierWithId(tierNames[i]); if (tiers[i] == null) { throw new QueryFormulationException(SearchLocale.getString( "Search.Exception.CannotFindTier") + " '" + tierNames[i] + "'"); } } } for (int i = 0; i < tiers.length; i++) { annotationHash.put(tiers[i].getName(), tiers[i].getAnnotations()); } //find unit tiers for dependent constraints if (Constraint.STRUCTURAL.equals(constraint.getMode())) { String tierName = constraint.getUnit().substring(0, constraint.getUnit().lastIndexOf(' ')); TierImpl unitTier = (TierImpl) transcription.getTierWithId(tierName); if (unitTier == null) { throw new QueryFormulationException(SearchLocale.getString( "Search.Exception.CannotFindTier") + " '" + tierName + "'"); } unitTierHash.put(constraint, unitTier); relationshipHash.put(constraint, getRelationship(unitTier, tiers[0])); if (!annotationHash.containsKey(tierName)) { List annotations = unitTier.getAnnotations(); annotationHash.put(tierName, annotations); } } } /* * traverse whole tree */ private void fillHashes(CorpusType type, Constraint constraint) throws QueryFormulationException { for (Enumeration e = constraint.children(); e.hasMoreElements();) { fillHashes(type, (Constraint) e.nextElement()); } fillAnnotationHash(constraint); patternHash.put(constraint, Utilities.getPattern(constraint, type)); } private void filterDependentConstraints(List startingMatches, Constraint constraint) throws NullPointerException { for (Enumeration e = constraint.children(); e.hasMoreElements();) { int j = 0; Constraint childConstraint = (Constraint) e.nextElement(); while (j < startingMatches.size()) { ElanMatch match = (ElanMatch) startingMatches.get(j); List childMatches = getChildMatches(match, childConstraint); if (((childConstraint.getQuantifier() == Constraint.ANY) && (childMatches.size() > 0)) || ((childConstraint.getQuantifier() == Constraint.NONE) && (childMatches.size() == 0))) { j++; match.addChildren(childMatches); } else { startingMatches.remove(j); } } } } /** * DOCUMENT ME! * * @param query DOCUMENT ME! * * @throws QueryFormulationException * @throws PatternSyntaxException */ private void initHashtables(ContentQuery query) throws QueryFormulationException, PatternSyntaxException { patternHash.clear(); annotationHash.clear(); unitTierHash.clear(); relationshipHash.clear(); fillHashes(query.getType(), query.getAnchorConstraint()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -