Example #1
0
  /**
   * Returns the Item in the given Relation associated with the given time.
   *
   * @param relation the name of the relation
   * @param time the time
   * @throws IllegalStateException if the Segment durations have not been calculated in the
   *     Utterance or if the given relation is not present in the Utterance
   */
  public Item getItem(String relation, float time) {

    Relation segmentRelation = null;

    if ((segmentRelation = getRelation(Relation.SEGMENT)) == null) {
      throw new IllegalStateException("Utterance has no Segment relation");
    }

    String pathName = null;

    if (relation.equals(Relation.SEGMENT)) {
      // do nothing
    } else if (relation.equals(Relation.SYLLABLE)) {
      pathName = "R:SylStructure.parent.R:Syllable";
    } else if (relation.equals(Relation.SYLLABLE_STRUCTURE)) {
      pathName = "R:SylStructure.parent.parent";
    } else if (relation.equals(Relation.WORD)) {
      pathName = "R:SylStructure.parent.parent.R:Word";
    } else if (relation.equals(Relation.TOKEN)) {
      pathName = "R:SylStructure.parent.parent.R:Token.parent";
    } else if (relation.equals(Relation.PHRASE)) {
      pathName = "R:SylStructure.parent.parent.R:Phrase.parent";
    } else {
      throw new IllegalArgumentException("Utterance.getItem(): relation cannot be " + relation);
    }

    PathExtractor path = new PathExtractorImpl(pathName, false);

    // get the Item in the Segment Relation with the given time
    Item segmentItem = SegmentRelationUtils.getItem(segmentRelation, time);

    if (relation.equals(Relation.SEGMENT)) {
      return segmentItem;
    } else if (segmentItem != null) {
      return path.findItem(segmentItem);
    } else {
      return null;
    }
  }
 @Override
 public boolean shouldProcessRecursively(WalkerContext context, StorageCollectionItem coll) {
   return collectionPredicate.apply(pathExtractor.extractCollectionItemPath(coll));
 }
 @Override
 public boolean shouldProcess(WalkerContext context, StorageItem item) {
   return itemPredicate.apply(pathExtractor.extractItemPath(item));
 }