使用GATE 8.0,并尝试使用Jape规则示例填充本体

时间:2015-11-30 00:19:04

标签: gate

我正在使用GATE 8.0,并尝试使用填充本体  GUIDE中提供的Jape规则示例但它不起作用且本体没有实例化!  请让我知道我做错了什么,你的帮助是  非常感谢。

 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 个答案:

没有答案