Beispiel #1
0
 public Step(Resolver resolver, Map attributes) {
   this(resolver, "");
   Log.debug("Instantiating " + getClass());
   if (Log.expectDebugOutput) {
     Iterator iter = attributes.keySet().iterator();
     while (iter.hasNext()) {
       String key = (String) iter.next();
       Log.debug(key + "=" + attributes.get(key));
     }
   }
   parseStepAttributes(attributes);
 }
Beispiel #2
0
 /** Add an attribute to the given XML Element. Attributes are kept in alphabetical order. */
 protected Element addAttributes(Element el) {
   // Use a TreeMap to keep the attributes sorted on output
   Map atts = new TreeMap(getAttributes());
   Iterator iter = atts.keySet().iterator();
   while (iter.hasNext()) {
     String key = (String) iter.next();
     String value = (String) atts.get(key);
     if (value == null) {
       Log.warn("Attribute '" + key + "' value was null in step " + getXMLTag());
       value = "";
     }
     el.setAttribute(key, value);
   }
   return el;
 }
Beispiel #3
0
  // given MorphItem
  private void getWithMorphItem(
      Word w, MorphItem mi, String targetPred, String targetRel, SignHash result)
      throws LexException {
    // get supertags for filtering, if a supertagger is installed
    Map<String, Double> supertags = null;
    Set<String> supertagsFound = null;
    if (_supertagger != null) {
      supertags = _supertagger.getSupertags();
      if (supertags != null) supertagsFound = new HashSet<String>(supertags.size());
    }

    // get macro adder
    MacroAdder macAdder = getMacAdder(mi);

    // if we have this stem in our lexicon
    String stem = mi.getWord().getStem();
    String pos = mi.getWord().getPOS();
    Set<EntriesItem[]> explicitEntries =
        null; // for storing entries from explicitly listed family members
    if (_stems.containsKey(stem + pos)) {
      explicitEntries = new HashSet<EntriesItem[]>();
      Collection<Object> stemItems = (Collection<Object>) _stems.get(stem + pos);
      for (Iterator<Object> I = stemItems.iterator(); I.hasNext(); ) {
        Object item = I.next();
        // see if it's an EntriesItem
        if (item instanceof EntriesItem) {
          EntriesItem entry = (EntriesItem) item;
          // do lookup
          getWithEntriesItem(
              w,
              mi,
              stem,
              stem,
              targetPred,
              targetRel,
              entry,
              macAdder,
              supertags,
              supertagsFound,
              result);
        }
        // otherwise it has to be a Pair containing a DataItem and
        // an EntriesItem[]
        else {
          @SuppressWarnings("rawtypes")
          DataItem dItem = (DataItem) ((Pair) item).a;
          @SuppressWarnings("rawtypes")
          EntriesItem[] entries = (EntriesItem[]) ((Pair) item).b;
          // store entries
          explicitEntries.add(entries);
          // do lookup
          getWithDataItem(
              w,
              mi,
              dItem,
              entries,
              targetPred,
              targetRel,
              macAdder,
              supertags,
              supertagsFound,
              result);
        }
      }
    }

    // for entries that are not explicitly in the lexicon file, we have to create
    // Signs from the open class entries with the appropriate part-of-speech
    Collection<EntriesItem[]> entrySets = (Collection<EntriesItem[]>) _posToEntries.get(pos);
    if (entrySets != null) {
      for (Iterator<EntriesItem[]> E = entrySets.iterator(); E.hasNext(); ) {
        EntriesItem[] entries = E.next();
        // skip if entries explicitly listed
        if (explicitEntries != null && explicitEntries.contains(entries)) continue;
        // otherwise get entries with pred = targetPred, or stem if null
        String pred = (targetPred != null) ? targetPred : stem;
        getWithDataItem(
            w,
            mi,
            new DataItem(stem, pred),
            entries,
            targetPred,
            targetRel,
            macAdder,
            supertags,
            supertagsFound,
            result);
      }
    }

    // finally do entries for any remaining supertags
    if (supertags != null) {
      for (String supertag : supertags.keySet()) {
        if (supertagsFound.contains(supertag)) continue;
        Set<EntriesItem> entries = _stagToEntries.get(supertag + pos);
        if (entries == null) continue; // nb: could be a POS mismatch
        // get entries with pred = targetPred, or stem if null
        String pred = (targetPred != null) ? targetPred : stem;
        for (EntriesItem entry : entries) {
          if (!entry.getStem().equals(DEFAULT_VAL)) continue;
          getWithEntriesItem(
              w,
              mi,
              stem,
              pred,
              targetPred,
              targetRel,
              entry,
              macAdder,
              supertags,
              supertagsFound,
              result);
        }
      }
    }
  }