Revision: 15982
          http://gate.svn.sourceforge.net/gate/?rev=15982&view=rev
Author:   valyt
Date:     2012-07-25 10:50:14 +0000 (Wed, 25 Jul 2012)
Log Message:
-----------
Implementations for the new SAH methods.
Some clean-up:
 - don't store the URICache value inside the indexConfig.xml file
 - removed duplicated implementation of checkInit() from abstract class
 

Modified Paths:
--------------
    
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java

Modified: 
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
===================================================================
--- 
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
        2012-07-25 10:49:07 UTC (rev 15981)
+++ 
mimir/trunk/plugins/sesame/src/gate/mimir/sesame/SesameSemanticAnnotationHelper.java
        2012-07-25 10:50:14 UTC (rev 15982)
@@ -106,10 +106,12 @@
        private static boolean staticInitDone = false;
 
        /**
-        * Flag for the initialisation. Set to <code>true</code> after the
-        * initialisation has completed.
+        * @deprecated this flag is not used any more, as the same logic is 
already 
+        * implemented in the init() methods on 
+        * {@link AbstractSemanticAnnotationHelper}. The field is not removed 
to allow
+        * old indexes to be opened.
         */
-       private boolean initDone = false;
+       private transient boolean initDone = false;
 
        /**
         * Parser used for SPARQL queries.
@@ -203,6 +205,11 @@
        protected URI annotationTemplateURILevel1;
 
        /**
+        * The prefix shared by all mention URIs produced by this helper.
+        */
+       protected String mentionUriPrefix;
+       
+       /**
         * The URI for the level 2 annotation template ontology class 
corresponding
         * to the current annotation type.
         */
@@ -227,7 +234,6 @@
        protected transient String[] uriFeatureNamesPlusSemanticConstraint;
 
        private static NumberFormat percentFormat;
-
        
   /**
    * When in document mode (see
@@ -238,7 +244,7 @@
   
        protected ValueFactory factory;
 
-       private URICache uriCache;
+       private transient URICache uriCache;
 
        // private RepositoryManager manager;
        protected transient RepositoryConnection connection;
@@ -249,8 +255,8 @@
        protected String sesameConfigLocation = "resources/owlim.ttl";
 
        protected String absoluteConfigLocation = "";
-       
-       public void setRelativePath(String relativePath) {
+
+  public void setRelativePath(String relativePath) {
          sesameConfigLocation = relativePath;
        }
        
@@ -265,8 +271,6 @@
 
        @Override
        public void init(Indexer indexer) {
-               if (initDone)
-                       return;
                super.init(indexer);
                setFloatFeatures(concatenateArrays(getIntegerFeatures(), 
getFloatFeatures()));
                setIntegerFeatures(new String[0]);
@@ -290,7 +294,6 @@
                        uriCache = new URICache(this);
                        docsSoFar = 0;
                        initCommon();
-                       initDone = true;
                } catch (RepositoryException e) {
                        logger.error(e);
                } catch (RepositoryConfigException e) {
@@ -302,8 +305,6 @@
 
        @Override
        public void init(QueryEngine queryEngine) {
-               if (initDone)
-                       return;
                super.init(queryEngine);
                try {
                        connection = 
getRepositoryConnection(queryEngine.getIndexConfig());
@@ -315,7 +316,6 @@
                        uriCache = new URICache(this);
                        docsSoFar = 0;
                        initCommon();
-                       initDone = true;
                } catch (RepositoryException e) {
                        logger.error(e);
                } catch (RepositoryConfigException e) {
@@ -340,9 +340,7 @@
   @Override
        public String[] getMentionUris(Annotation ann, int length,
                        Indexer indexer) {
-               if (!initDone) {
-                       init(indexer);
-               }
+               if (!isInited())  init(indexer);
                
     FeatureMap featuresToIndex;
     if(getMode() == Mode.DOCUMENT) {
@@ -369,8 +367,7 @@
        @Override
        public List<Mention> getMentions(String annotationType,
                        List<Constraint> constraints, QueryEngine engine) {
-               if (!initDone)
-                       init(engine);
+               if (!isInited()) init(engine);
                StringBuilder atQuery = new StringBuilder(
                                "?annotationTemplateInstance " + "<" + 
RDF.TYPE.stringValue()
                                                + "> " + "<" + 
annotationTemplateURILevel1 + "> .\n");
@@ -526,9 +523,17 @@
                return new ArrayList<Mention>();
        }
 
-       @Override
+       /* (non-Javadoc)
+   * @see gate.mimir.SemanticAnnotationHelper#isMentionUri(java.lang.String)
+   */
+  @Override
+  public boolean isMentionUri(String mentionUri) {
+    return mentionUri.startsWith(mentionUriPrefix);
+  }
+
+  @Override
        public void close(Indexer indexer) {
-               if (initDone) {
+               if (isInited()) {
                        logger.info("Closing Sesame Repository Connection");
                        try {
                                connection.commit();
@@ -539,7 +544,6 @@
                        }
                        connection = null;
                        parser = null;
-                       initDone = false;
                        // if we're the last helper, shutdown the ORDI source
                        int clientCount = (Integer) 
indexer.getIndexConfig().getContext()
                                        .get(SESAME_CONNECTION_COUNT_KEY);
@@ -564,7 +568,7 @@
 
        @Override
        public void close(QueryEngine qEngine) {
-               if (initDone) {
+               if (isInited()) {
                        logger.info("Closing Sesame Repository Connection");
                        try {
                                connection.commit();
@@ -575,7 +579,6 @@
                        }
                        connection = null;
                        parser = null;
-                       initDone = false;
                        // if we're the last helper, shutdown the ORDI source
                        int clientCount = (Integer) 
qEngine.getIndexConfig().getContext()
                                        .get(SESAME_CONNECTION_COUNT_KEY);
@@ -807,7 +810,10 @@
                                        uriFeatureNames.length);
                        
uriFeatureNamesPlusSemanticConstraint[uriFeatureNames.length] = 
SEMANTIC_CONSTRAINT_FEATURE;
                }
-               initDone = true;
+               
+               // compute the mentions URI prefix
+               mentionUriPrefix =  factory.createURI(MIMIR_NAMESPACE, 
annotationType )
+                   .stringValue();
        }
 
        /**

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to