You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by to...@apache.org on 2011/02/20 17:27:29 UTC

svn commit: r1072624 - in /uima/sandbox/trunk/Solrcas/src: main/java/org/apache/uima/solrcas/SolrCASConsumer.java test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java

Author: tommaso
Date: Sun Feb 20 16:27:28 2011
New Revision: 1072624

URL: http://svn.apache.org/viewvc?rev=1072624&view=rev
Log:
[UIMA-2036] - removed parameters from createServer() method

Modified:
    uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java
    uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java

Modified: uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java?rev=1072624&r1=1072623&r2=1072624&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java (original)
+++ uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java Sun Feb 20 16:27:28 2011
@@ -45,14 +45,10 @@ public class SolrCASConsumer extends Cas
 
   @Override
   public void initialize(UimaContext context) throws ResourceInitializationException {
+    super.initialize(context);
     try {
-      /* get Solr type*/
-      String solrInstanceTypeParam = String.valueOf(context.getConfigParameterValue("solrInstanceType"));
-
-      /* get Solr Path */
-      String solrPathParam = String.valueOf(context.getConfigParameterValue("solrPath"));
-
-      this.solrServer = createServer(solrInstanceTypeParam, solrPathParam);
+      /* create the SolrServer*/
+      this.solrServer = createServer();
 
       /* read configuration */
       FieldMappingReader fieldMappingReader = new FieldMappingReader();
@@ -63,59 +59,66 @@ public class SolrCASConsumer extends Cas
       context.getLogger().log(Level.SEVERE, e.toString());
       throw new ResourceInitializationException(e);
     }
-    super.initialize(context);
   }
 
-  protected SolrServer createServer(String solrInstanceTypeParam, String solrPathParam) throws Exception {
+  protected SolrServer createServer() throws Exception {
+    /* get Solr type*/
+    String solrInstanceTypeParam = String.valueOf(getContext().
+            getConfigParameterValue("solrInstanceType"));
+
+    /* get Solr Path */
+    String solrPathParam = String.valueOf(getContext().
+            getConfigParameterValue("solrPath"));
+
     SolrServer solrServer = null;
     if (solrInstanceTypeParam.equalsIgnoreCase("http")) {
       URL solrURL = URI.create(solrPathParam).toURL();
       solrServer = new CommonsHttpSolrServer(solrURL);
-    } 
-    
+    }
+
     return solrServer;
   }
 
   public void process(CAS cas) throws AnalysisEngineProcessException {
-	  
-      SolrInputDocument document = new SolrInputDocument();
-      if (mappingConfig.getCasMapping()!=null && mappingConfig.getCasMapping().length()>0)
-        document.addField(mappingConfig.getCasMapping(), cas.toString());
-      if (mappingConfig.getDocumentTextMapping()!=null && mappingConfig.getDocumentTextMapping().length()>0)
-        document.addField(mappingConfig.getDocumentTextMapping(), cas.getDocumentText());
-      if (mappingConfig.getDocumentLanguageMapping()!=null && mappingConfig.getDocumentLanguageMapping().length()>0)
-        document.addField(mappingConfig.getDocumentLanguageMapping(), cas.getDocumentLanguage());
-      for (String key : mappingConfig.getFeatureStructuresMapping().keySet()) {
-        Type type = cas.getTypeSystem().getType(key);
-        
-        for (FSIterator<FeatureStructure> iterator = cas.getIndexRepository().getAllIndexedFS(type); iterator
-                .hasNext();) {
-          FeatureStructure fs = iterator.next();
-          Map<String, String> stringStringMap = mappingConfig.getFeatureStructuresMapping().get(key);
-          
-          for (String featureName : stringStringMap.keySet()) {
-        	  
-            String fieldName = stringStringMap.get(featureName);
-
-            String featureValue;
-            
-            if (fs instanceof AnnotationFS && "coveredText".equals(featureName)) {
-              featureValue = ((AnnotationFS) fs).getCoveredText();
-            } else {
-              Feature feature = type.getFeatureByBaseName(featureName);
-              featureValue = fs.getFeatureValueAsString(feature);
-            }
-            
-            document.addField(fieldName, featureValue);
+
+    SolrInputDocument document = new SolrInputDocument();
+    if (mappingConfig.getCasMapping() != null && mappingConfig.getCasMapping().length() > 0)
+      document.addField(mappingConfig.getCasMapping(), cas.toString());
+    if (mappingConfig.getDocumentTextMapping() != null && mappingConfig.getDocumentTextMapping().length() > 0)
+      document.addField(mappingConfig.getDocumentTextMapping(), cas.getDocumentText());
+    if (mappingConfig.getDocumentLanguageMapping() != null && mappingConfig.getDocumentLanguageMapping().length() > 0)
+      document.addField(mappingConfig.getDocumentLanguageMapping(), cas.getDocumentLanguage());
+    for (String key : mappingConfig.getFeatureStructuresMapping().keySet()) {
+      Type type = cas.getTypeSystem().getType(key);
+
+      for (FSIterator<FeatureStructure> iterator = cas.getIndexRepository().getAllIndexedFS(type); iterator
+              .hasNext();) {
+        FeatureStructure fs = iterator.next();
+        Map<String, String> stringStringMap = mappingConfig.getFeatureStructuresMapping().get(key);
+
+        for (String featureName : stringStringMap.keySet()) {
+
+          String fieldName = stringStringMap.get(featureName);
+
+          String featureValue;
+
+          if (fs instanceof AnnotationFS && "coveredText".equals(featureName)) {
+            featureValue = ((AnnotationFS) fs).getCoveredText();
+          } else {
+            Feature feature = type.getFeatureByBaseName(featureName);
+            featureValue = fs.getFeatureValueAsString(feature);
           }
+
+          document.addField(fieldName, featureValue);
         }
       }
-      
-      try {
-        solrServer.add(document);
-        solrServer.commit();
-	  } catch (Exception e) {
-	    throw new AnalysisEngineProcessException(e);
-	  }
+    }
+
+    try {
+      solrServer.add(document);
+      solrServer.commit();
+    } catch (Exception e) {
+      throw new AnalysisEngineProcessException(e);
+    }
   }
 }

Modified: uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java?rev=1072624&r1=1072623&r2=1072624&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java (original)
+++ uima/sandbox/trunk/Solrcas/src/test/java/org/apache/uima/solrcas/EmbeddedSolrCASConsumer.java Sun Feb 20 16:27:28 2011
@@ -28,9 +28,13 @@ import java.net.URL;
 public class EmbeddedSolrCASConsumer extends SolrCASConsumer {
 
   @Override
-  protected SolrServer createServer(String solrInstanceTypeParam,
-                                    String solrPathParam) throws Exception {
+  protected SolrServer createServer() throws Exception {
     SolrServer solrServer = null;
+    String solrInstanceTypeParam = String.valueOf(getContext().
+            getConfigParameterValue("solrInstanceType"));
+
+    String solrPathParam = String.valueOf(getContext().
+            getConfigParameterValue("solrPath"));
 
     if (solrInstanceTypeParam.equals("embedded")) {
       URL solrURL = FileUtils.getURL(solrPathParam);