1

I am using GATE 8.0, and trying to populate an ontology using the Jape rule example provided in GUIDE but it doesn't work and the ontology doesn't instantiated!!! Please let me know what it is that I am doing wrong, and your help is greatly appreciated.

 Phase: MentionEntities
    Input: Token Lookup
Options: control = appelt debug = true

Rule: FindEntities
({Mention}):mention
-->
:mention{
  //find the annotation matched by LHS
  //we know the annotation set returned
  //will always contain a single annotation
  Annotation mentionAnn = mentionAnnots.iterator().next();

  //find the class of the mention
  String className = (String)mentionAnn.getFeatures().
    get(gate.creole.ANNIEConstants.LOOKUP_CLASS_FEATURE_NAME);
  // should normalize class name and avoid invalid class names here!
  OClass aClass = ontology.getOClass(ontology.createOURIForName(className));
  if(aClass == null) { 
    System.err.println("Error class \"" + className + "\" does not exist!");
    return; 
  } 

  //find the text covered by the annotation
  String theMentionText = gate.Utils.stringFor(doc, mentionAnn);

  // when creating a URI from text that came from a document you must take care
  // to ensure that the name does not contain any characters that are illegal
  // in a URI.  The following method does this nicely for English but you may
  // want to do your own normalization instead if you have non-English text.
  String mentionName = OUtils.toResourceName(theMentionText);

  // get the property to store mention texts for mention instances
  DatatypeProperty prop =
    ontology.getDatatypeProperty(ontology.createOURIForName("mentionText"));

  OURI mentionURI = ontology.createOURIForName(mentionName);
  // if that mention instance does not already exist, add it
  if (!ontology.containsOInstance(mentionURI)) {
    OInstance inst = ontology.addOInstance(mentionURI, aClass);
    // add the actual mention text to the instance
    try {
      inst.addDatatypePropertyValue(prop, 
        new Literal(theMentionText, OConstants.ENGLISH));
    }
    catch(InvalidValueException e) {
      throw new JapeException(e);
    }
  }
}

0 Answers0