You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/05/16 12:01:48 UTC

svn commit: r1339101 - /incubator/stanbol/branches/celi-enhancement-engines/engines/celi/src/main/java/org/apache/stanbol/enhancer/engines/celi/lemmatizer/impl/CeliLemmatizerEnhancementEngine.java

Author: rwesten
Date: Wed May 16 10:01:47 2012
New Revision: 1339101

URL: http://svn.apache.org/viewvc?rev=1339101&view=rev
Log:
STANBOL-583: Ensures write locks are used while writing Enhancements in the CELI Lemmatizer engine.

In my opinnion the Lemmatizer Engine is now ready to use. However I would really like to see unit tests for longer tests with special chars to ensure the absence of similar issues as for the CELI NER engine before giving a final green light. 

Modified:
    incubator/stanbol/branches/celi-enhancement-engines/engines/celi/src/main/java/org/apache/stanbol/enhancer/engines/celi/lemmatizer/impl/CeliLemmatizerEnhancementEngine.java

Modified: incubator/stanbol/branches/celi-enhancement-engines/engines/celi/src/main/java/org/apache/stanbol/enhancer/engines/celi/lemmatizer/impl/CeliLemmatizerEnhancementEngine.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/celi-enhancement-engines/engines/celi/src/main/java/org/apache/stanbol/enhancer/engines/celi/lemmatizer/impl/CeliLemmatizerEnhancementEngine.java?rev=1339101&r1=1339100&r2=1339101&view=diff
==============================================================================
--- incubator/stanbol/branches/celi-enhancement-engines/engines/celi/src/main/java/org/apache/stanbol/enhancer/engines/celi/lemmatizer/impl/CeliLemmatizerEnhancementEngine.java (original)
+++ incubator/stanbol/branches/celi-enhancement-engines/engines/celi/src/main/java/org/apache/stanbol/enhancer/engines/celi/lemmatizer/impl/CeliLemmatizerEnhancementEngine.java Wed May 16 10:01:47 2012
@@ -187,13 +187,24 @@ public class CeliLemmatizerEnhancementEn
 			return;
 		}
 
-		try {
-			
-			MGraph g = ci.getMetadata();
-			LiteralFactory literalFactory = LiteralFactory.getInstance();
+		MGraph g = ci.getMetadata();
+		LiteralFactory literalFactory = LiteralFactory.getInstance();
 
-			if (this.completeMorphoAnalysis) {
-				List<LexicalEntry> terms = this.client.performMorfologicalAnalysis(text, language);
+		if (this.completeMorphoAnalysis) {
+		    List<LexicalEntry> terms;
+	        try {
+	            terms = this.client.performMorfologicalAnalysis(text, language);
+	        } catch (IOException e) {
+	            throw new EngineException("Error while calling the CELI Lemmatizer"
+	                +" service (configured URL: "
+	                +serviceURL+")!",e);
+	        } catch (SOAPException e) {
+	            throw new EngineException("Error wile encoding/decoding the request/"
+	                +"response to the CELI lemmatizer service!",e);
+	        }
+	        //get a write lock before writing the enhancements
+	        ci.getLock().writeLock().lock();
+	        try {
 				for (LexicalEntry le : terms) {
 				    if(!le.termReadings.isEmpty()){
     					UriRef textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
@@ -215,22 +226,31 @@ public class CeliLemmatizerEnhancementEn
     					}
 				    } //TODO: check if it is OK to ignore lexical entries with no readings
 				}
-			} else {
-				String lemmatizedContents = this.client.lemmatizeContents(text, language);
-
+	        } finally {
+	            ci.getLock().writeLock().unlock();
+	        }
+		} else {
+		    String lemmatizedContents;
+	        try {
+	            lemmatizedContents = this.client.lemmatizeContents(text, language);
+            } catch (IOException e) {
+                throw new EngineException("Error while calling the CELI Lemmatizer"
+                    +" service (configured URL: "
+                    +serviceURL+")!",e);
+            } catch (SOAPException e) {
+                throw new EngineException("Error wile encoding/decoding the request/"
+                    +"response to the CELI lemmatizer service!",e);
+            }
+            //get a write lock before writing the enhancements
+            ci.getLock().writeLock().lock();
+            try {
 				UriRef textEnhancement = EnhancementEngineHelper.createTextEnhancement(ci, this);
 				g.add(new TripleImpl(textEnhancement, hasLemmaForm, 
 				    new PlainLiteralImpl(lemmatizedContents,lang)));
-			}
-        } catch (IOException e) {
-            throw new EngineException("Error while calling the CELI Lemmatizer"
-                +" service (configured URL: "
-                +serviceURL+")!",e);
-        } catch (SOAPException e) {
-            throw new EngineException("Error wile encoding/decoding the request/"
-                +"response to the CELI lemmatizer service!",e);
-        } 
-
+            } finally {
+                ci.getLock().writeLock().unlock();
+            }
+		}
 	}
 
 	private boolean isLangSupported(String language) {