[SOLR-3902] - adding super constructor to FieldMappingException, adding final modifiers where possible, substituting StringBuffer with StringBuilder where possible, for each loops

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1397452 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tommaso Teofili 2012-10-12 06:41:55 +00:00
parent 72a4fd2978
commit 2e01a46f8c
5 changed files with 25 additions and 23 deletions

View File

@ -18,9 +18,10 @@ package org.apache.solr.uima.processor;
*/ */
/** /**
* Exception thrown when an error happening while mapping UIMA CAS model to Solt fields * Exception thrown when an error happening while mapping UIMA CAS model to Solr fields
*/ */
public class FieldMappingException extends Exception { public class FieldMappingException extends Exception {
public FieldMappingException(Exception e) { public FieldMappingException(Exception e) {
super(e);
} }
} }

View File

@ -26,19 +26,19 @@ import java.util.Map;
*/ */
public class SolrUIMAConfiguration { public class SolrUIMAConfiguration {
private String[] fieldsToAnalyze; private final String[] fieldsToAnalyze;
private boolean fieldsMerging; private final boolean fieldsMerging;
private Map<String, Map<String, MapField>> typesFeaturesFieldsMapping; private final Map<String, Map<String, MapField>> typesFeaturesFieldsMapping;
private String aePath; private final String aePath;
private Map<String, Object> runtimeParameters; private final Map<String, Object> runtimeParameters;
private boolean ignoreErrors; private final boolean ignoreErrors;
private String logField; private final String logField;
SolrUIMAConfiguration(String aePath, String[] fieldsToAnalyze, boolean fieldsMerging, SolrUIMAConfiguration(String aePath, String[] fieldsToAnalyze, boolean fieldsMerging,
Map<String, Map<String, MapField>> typesFeaturesFieldsMapping, Map<String, Map<String, MapField>> typesFeaturesFieldsMapping,
@ -82,7 +82,8 @@ public class SolrUIMAConfiguration {
static final class MapField { static final class MapField {
private String fieldName, fieldNameFeature; private String fieldName;
private final String fieldNameFeature;
private boolean prefix; // valid if dynamicField == true private boolean prefix; // valid if dynamicField == true
// false: *_s, true: s_* // false: *_s, true: s_*

View File

@ -32,7 +32,7 @@ import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField;
*/ */
public class SolrUIMAConfigurationReader { public class SolrUIMAConfigurationReader {
private NamedList<Object> args; private final NamedList<Object> args;
public SolrUIMAConfigurationReader(NamedList<Object> args) { public SolrUIMAConfigurationReader(NamedList<Object> args) {
this.args = args; this.args = args;

View File

@ -38,9 +38,9 @@ public class UIMAToSolrMapper {
private final Logger log = LoggerFactory.getLogger(UIMAToSolrMapper.class); private final Logger log = LoggerFactory.getLogger(UIMAToSolrMapper.class);
private SolrInputDocument document; private final SolrInputDocument document;
private JCas cas; private final JCas cas;
public UIMAToSolrMapper(SolrInputDocument document, JCas cas) { public UIMAToSolrMapper(SolrInputDocument document, JCas cas) {
this.document = document; this.document = document;
@ -64,15 +64,15 @@ public class UIMAToSolrMapper {
String fieldNameFeatureValue = fieldNameFeature == null ? null : String fieldNameFeatureValue = fieldNameFeature == null ? null :
fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature)); fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
String fieldName = mapField.getFieldName(fieldNameFeatureValue); String fieldName = mapField.getFieldName(fieldNameFeatureValue);
log.info(new StringBuffer("mapping ").append(typeName).append("@").append(featureName) log.info(new StringBuilder("mapping ").append(typeName).append("@").append(featureName)
.append(" to ").append(fieldName).toString()); .append(" to ").append(fieldName).toString());
String featureValue = null; String featureValue;
if (fs instanceof Annotation && "coveredText".equals(featureName)) { if (fs instanceof Annotation && "coveredText".equals(featureName)) {
featureValue = ((Annotation) fs).getCoveredText(); featureValue = ((Annotation) fs).getCoveredText();
} else { } else {
featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName)); featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
} }
log.info(new StringBuffer("writing ").append(featureValue).append(" in ").append( log.info(new StringBuilder("writing ").append(featureValue).append(" in ").append(
fieldName).toString()); fieldName).toString());
document.addField(fieldName, featureValue, 1.0f); document.addField(fieldName, featureValue, 1.0f);
} }

View File

@ -73,16 +73,16 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
/* get the fields to analyze */ /* get the fields to analyze */
String[] texts = getTextsToAnalyze(solrInputDocument); String[] texts = getTextsToAnalyze(solrInputDocument);
for (int i = 0; i < texts.length; i++) { for (String currentText : texts) {
text = texts[i]; text = currentText;
if (text != null && text.length()>0) { if (text != null && text.length() > 0) {
/* process the text value */ /* process the text value */
JCas jcas = processText(text); JCas jcas = processText(text);
UIMAToSolrMapper uimaToSolrMapper = new UIMAToSolrMapper(solrInputDocument, jcas); UIMAToSolrMapper uimaToSolrMapper = new UIMAToSolrMapper(solrInputDocument, jcas);
/* get field mapping from config */ /* get field mapping from config */
Map<String, Map<String, MapField>> typesAndFeaturesFieldsMap = solrUIMAConfiguration Map<String, Map<String, MapField>> typesAndFeaturesFieldsMap = solrUIMAConfiguration
.getTypesFeaturesFieldsMapping(); .getTypesFeaturesFieldsMapping();
/* map type features on fields */ /* map type features on fields */
for (String typeFQN : typesAndFeaturesFieldsMap.keySet()) { for (String typeFQN : typesAndFeaturesFieldsMap.keySet()) {
uimaToSolrMapper.map(typeFQN, typesAndFeaturesFieldsMap.get(typeFQN)); uimaToSolrMapper.map(typeFQN, typesAndFeaturesFieldsMap.get(typeFQN));
@ -133,8 +133,8 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
String[] textVals; String[] textVals;
if (merge) { if (merge) {
StringBuilder unifiedText = new StringBuilder(""); StringBuilder unifiedText = new StringBuilder("");
for (int i = 0; i < fieldsToAnalyze.length; i++) { for (String aFieldsToAnalyze : fieldsToAnalyze) {
unifiedText.append(String.valueOf(solrInputDocument.getFieldValue(fieldsToAnalyze[i]))); unifiedText.append(String.valueOf(solrInputDocument.getFieldValue(aFieldsToAnalyze)));
} }
textVals = new String[1]; textVals = new String[1];
textVals[0] = unifiedText.toString(); textVals[0] = unifiedText.toString();
@ -150,7 +150,7 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
/* process a field value executing UIMA the CAS containing it as document text */ /* process a field value executing UIMA the CAS containing it as document text */
private JCas processText(String textFieldValue) throws ResourceInitializationException, private JCas processText(String textFieldValue) throws ResourceInitializationException,
AnalysisEngineProcessException { AnalysisEngineProcessException {
log.info(new StringBuffer("Analyzing text").toString()); log.info(new StringBuilder("Analyzing text").toString());
/* get the UIMA analysis engine */ /* get the UIMA analysis engine */
AnalysisEngine ae = aeProvider.getAE(); AnalysisEngine ae = aeProvider.getAE();
@ -160,7 +160,7 @@ public class UIMAUpdateRequestProcessor extends UpdateRequestProcessor {
/* perform analysis on text field */ /* perform analysis on text field */
ae.process(jcas); ae.process(jcas);
log.info(new StringBuilder("Text processing completed").toString()); log.info("Text processing completed");
return jcas; return jcas;
} }