Esempio n. 1
0
 public static Class lookupAnnotationKey(Env env, String name) {
   if (env != null) {
     Object obj = env.get(name);
     if (obj != null) {
       if (obj instanceof Class) {
         return (Class) obj;
       }
       //        else if (obj instanceof Value) {
       //          obj = ((Value) obj).get();
       //          if (obj instanceof Class) {
       //            return (Class) obj;
       //          }
       //        }
     }
   }
   AnnotationLookup.KeyLookup lookup = AnnotationLookup.getCoreKey(name);
   if (lookup != null) {
     return lookup.coreKey;
   } else {
     try {
       Class clazz = Class.forName(name);
       return clazz;
     } catch (ClassNotFoundException ex) {
     }
     return null;
   }
 }
Esempio n. 2
0
  @SuppressWarnings("unchecked")
  public boolean nodeAttrMatch(IndexedWord node, final SemanticGraph sg, boolean ignoreCase) {
    // System.out.println(node.word());
    if (isRoot) return (negDesc ? !sg.getRoots().contains(node) : sg.getRoots().contains(node));
    // System.out.println("not root");
    if (isEmpty)
      return (negDesc ? !node.equals(IndexedWord.NO_WORD) : node.equals(IndexedWord.NO_WORD));

    // System.err.println("Attributes are: " + attributes);
    for (Map.Entry<String, Pattern> attr : attributes.entrySet()) {
      String key = attr.getKey();
      // System.out.println(key);
      String nodeValue;
      // if (key.equals("idx"))
      // nodeValue = Integer.toString(node.index());
      // else {

      Class c = Env.lookupAnnotationKey(env, key);
      // find class for the key

      Object value = node.get(c);
      if (value == null) nodeValue = null;
      else nodeValue = value.toString();
      // }
      // System.out.println(nodeValue);
      if (nodeValue == null) return negDesc;
      Pattern valuePattern = attr.getValue();
      boolean matches = false;
      if (ignoreCase) {
        if (Pattern.compile(valuePattern.pattern(), Pattern.CASE_INSENSITIVE)
            .matcher(nodeValue)
            .matches()) matches = true;
      } else {
        if (nodeValue.matches(valuePattern.pattern())) matches = true;
      }
      if (!matches) {

        // System.out.println("doesn't match");
        // System.out.println("");
        return negDesc;
      }
    }
    // System.out.println("matches");
    // System.out.println("");
    return !negDesc;
  }