[Gate-users] Fwd: Populating Ontologies in Java using Gate Application Pipeline

Lida Ghahremanlou lida.ghahremanlou at gmail.com
Mon Oct 5 14:07:54 CEST 2015

---------- Forwarded message ----------
From: "Lida Ghahremanlou" <lida.ghahremanlou at gmail.com>
Date: 5 Oct 2015 7:43 pm
Subject: Populating Ontologies in Java using Gate Application Pipeline
To: <gate-users-request at lists.opengatecollaboration.org>


I have two queries (Question A and Question B) for populating Ontologies
using Gate application in Java. Here is the steps that I have successfully
implemented in my java program:

   1. I created a customized pipeline with mylist.def and my own
   gazetteers, which successfully annotated the sample corpus ( a list of
   tweets) loaded in GUI.
   2.  I then extracted the application pipeline and used it in the
   BatchGate program (given from this code) which also successfully annotated
   and extract the buildin xml file.
   3. Next, I wanted to populate my ontology using the annotation text,
   following the code explain in the jape rule and 46 and 47 slides(

   4. However, my java program can read and populate and write the ontology
   file successfully but, the program does not exit. Tracing the code  gave me
   the impression that loading the existing ontology causes this issue:

   // init GATE and load plugin as before...

   URL owl = new File("ontology.owl").toURI().toURL();
   FeatureMap params = Factory.newFeatureMap();
   params.put("rdfXmlURL", owl);
   Ontology theOntology = (Ontology)Factory.createResource(


   *Question A:* How can I solve this? I read something about Ontology
URL mappings.Can anyone give me more details?

   7. After that I pass this problem, I want to populate my ontology per
   annotation. Each annotation is a class. Meaning that I annotated each
   tweets as a sentence and then within each sentence, I want the other
   annotations. e.g.

*Tweet: #Ausopen Rafa won Rajor! Such a match*

*<Sentence> AusOpen <Player> Rafa </Player> won  <Player>Rajor</Player> !
Such a match </Sentence> *
I have written the code from the Jape example, however I still cannot get
the annotation within each sentence tag.
*Question B: How I can get the annotation within another annotation to
populate my ontology? *

   /find the annotation matched by LHS
  //we know the annotation set returned
  //will always contain a single annotation
  Annotation mentionAnn = mentionAnnots.iterator().next();
  //System.err.println("Annotation lenght : " + mentionAnn.lenght);

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

  //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
  // to ensure that the name does not contain any characters that are
  // in a URI.  The following method does this nicely for English but you
  // 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 =

  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);

Thank you for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opengatecollaboration.org/mailman/private/gate-users/attachments/20151005/e9857aa0/attachment.html>

More information about the Gate-users mailing list