當前位置: 首頁>>代碼示例>>Java>>正文


Java MapField類代碼示例

本文整理匯總了Java中org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField的典型用法代碼示例。如果您正苦於以下問題:Java MapField類的具體用法?Java MapField怎麽用?Java MapField使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MapField類屬於org.apache.solr.uima.processor.SolrUIMAConfiguration包,在下文中一共展示了MapField類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMultiMap

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
@Test
public void testMultiMap() {
  SolrCore core = h.getCore();
  UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("uima-multi-map");
  assertNotNull(chained);
  UIMAUpdateRequestProcessorFactory factory = (UIMAUpdateRequestProcessorFactory) chained
          .getFactories()[0];
  assertNotNull(factory);
  UpdateRequestProcessor processor = factory.getInstance(req(), null, null);
  assertTrue(processor instanceof UIMAUpdateRequestProcessor);
  SolrUIMAConfiguration conf = ((UIMAUpdateRequestProcessor)processor).solrUIMAConfiguration;
  Map<String, Map<String, MapField>> map = conf.getTypesFeaturesFieldsMapping();
  Map<String, MapField> subMap = map.get("a-type-which-can-have-multiple-features");
  assertEquals(2, subMap.size());
  assertEquals("1", subMap.get("A").getFieldName(null));
  assertEquals("2", subMap.get("B").getFieldName(null));
}
 
開發者ID:europeana,項目名稱:search,代碼行數:18,代碼來源:UIMAUpdateRequestProcessorTest.java

示例2: readTypesFeaturesFieldsMapping

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
private Map<String, Map<String, MapField>> readTypesFeaturesFieldsMapping() {
  Map<String, Map<String, MapField>> map = new HashMap<>();

  NamedList fieldMappings = (NamedList) args.get("fieldMappings");
  /* iterate over UIMA types */
  for (int i = 0; i < fieldMappings.size(); i++) {
    NamedList type = (NamedList) fieldMappings.get("type", i);
    String typeName = (String)type.get("name");

    Map<String, MapField> subMap = new HashMap<>();
    /* iterate over mapping definitions */
    for(int j = 0; j < type.size() - 1; j++){
      NamedList mapping = (NamedList) type.get("mapping", j + 1);
      String featureName = (String) mapping.get("feature");
      String fieldNameFeature = null;
      String mappedFieldName = (String) mapping.get("field");
      if(mappedFieldName == null){
        fieldNameFeature = (String) mapping.get("fieldNameFeature");
        mappedFieldName = (String) mapping.get("dynamicField");
      }
      if(mappedFieldName == null)
        throw new RuntimeException("either of field or dynamicField should be defined for feature " + featureName);
      MapField mapField = new MapField(mappedFieldName, fieldNameFeature);
      subMap.put(featureName, mapField);
    }
    map.put(typeName, subMap);
  }
  return map;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:31,代碼來源:SolrUIMAConfigurationReader.java

示例3: map

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
/**
 * map features of a certain UIMA type to corresponding Solr fields based on the mapping
 *
 * @param typeName             name of UIMA type to map
 */
void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
  try {
    Type type = cas.getTypeSystem().getType(typeName);
    for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator
        .hasNext(); ) {
      FeatureStructure fs = iterator.next();
      for (String featureName : featureFieldsmapping.keySet()) {
        MapField mapField = featureFieldsmapping.get(featureName);
        String fieldNameFeature = mapField.getFieldNameFeature();
        String fieldNameFeatureValue = fieldNameFeature == null ? null :
            fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
        String fieldName = mapField.getFieldName(fieldNameFeatureValue);
        if (log.isInfoEnabled()) {
          log.info("mapping {}@{} to {}", new Object[]{typeName, featureName, fieldName});
        }
        String featureValue = null;
        if (fs instanceof Annotation && "coveredText".equals(featureName)) {
          featureValue = ((Annotation) fs).getCoveredText();
        } else {
          featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
        }
        if (log.isDebugEnabled()) {
          log.debug("writing {} in {}", new Object[]{featureValue, fieldName});
        }
        document.addField(fieldName, featureValue, 1.0f);
      }
    }
  } catch (Exception e) {
    throw new FieldMappingException(e);
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:37,代碼來源:UIMAToSolrMapper.java

示例4: readTypesFeaturesFieldsMapping

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
private Map<String, Map<String, MapField>> readTypesFeaturesFieldsMapping() {
  Map<String, Map<String, MapField>> map = new HashMap<String, Map<String, MapField>>();

  NamedList fieldMappings = (NamedList) args.get("fieldMappings");
  /* iterate over UIMA types */
  for (int i = 0; i < fieldMappings.size(); i++) {
    NamedList type = (NamedList) fieldMappings.get("type", i);
    String typeName = (String)type.get("name");

    Map<String, MapField> subMap = new HashMap<String, MapField>();
    /* iterate over mapping definitions */
    for(int j = 0; j < type.size() - 1; j++){
      NamedList mapping = (NamedList) type.get("mapping", j + 1);
      String featureName = (String) mapping.get("feature");
      String fieldNameFeature = null;
      String mappedFieldName = (String) mapping.get("field");
      if(mappedFieldName == null){
        fieldNameFeature = (String) mapping.get("fieldNameFeature");
        mappedFieldName = (String) mapping.get("dynamicField");
      }
      if(mappedFieldName == null)
        throw new RuntimeException("either of field or dynamicField should be defined for feature " + featureName);
      MapField mapField = new MapField(mappedFieldName, fieldNameFeature);
      subMap.put(featureName, mapField);
    }
    map.put(typeName, subMap);
  }
  return map;
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:31,代碼來源:SolrUIMAConfigurationReader.java

示例5: map

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
/**
 * map features of a certain UIMA type to corresponding Solr fields based on the mapping
 *
 * @param typeName             name of UIMA type to map
 */
void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
  try {
    Type type = cas.getTypeSystem().getType(typeName);
    for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator
        .hasNext(); ) {
      FeatureStructure fs = iterator.next();
      for (String featureName : featureFieldsmapping.keySet()) {
        MapField mapField = featureFieldsmapping.get(featureName);
        String fieldNameFeature = mapField.getFieldNameFeature();
        String fieldNameFeatureValue = fieldNameFeature == null ? null :
            fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
        String fieldName = mapField.getFieldName(fieldNameFeatureValue);
        log.info(new StringBuffer("mapping ").append(typeName).append("@").append(featureName)
            .append(" to ").append(fieldName).toString());
        String featureValue = null;
        if (fs instanceof Annotation && "coveredText".equals(featureName)) {
          featureValue = ((Annotation) fs).getCoveredText();
        } else {
          featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
        }
        log.info(new StringBuffer("writing ").append(featureValue).append(" in ").append(
            fieldName).toString());
        document.addField(fieldName, featureValue, 1.0f);
      }
    }
  } catch (Exception e) {
    throw new FieldMappingException(e);
  }
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:35,代碼來源:UIMAToSolrMapper.java

示例6: processAdd

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
  String text = null;
  try {
    /* get Solr document */
    SolrInputDocument solrInputDocument = cmd.getSolrInputDocument();

    /* get the fields to analyze */
    String[] texts = getTextsToAnalyze(solrInputDocument);
    for (int i = 0; i < texts.length; i++) {
      text = texts[i];
      if (text != null && text.length()>0) {
        /* create a JCas which contain the text to analyze */
        JCas jcas = pool.getJCas(0);
        try {
          /* process the text value */
          processText(text, jcas);

          UIMAToSolrMapper uimaToSolrMapper = new UIMAToSolrMapper(
              solrInputDocument, jcas);
          /* get field mapping from config */
          Map<String,Map<String,MapField>> typesAndFeaturesFieldsMap = solrUIMAConfiguration
              .getTypesFeaturesFieldsMapping();
          /* map type features on fields */
          for (Entry<String,Map<String,MapField>> entry : typesAndFeaturesFieldsMap
              .entrySet()) {
            uimaToSolrMapper.map(entry.getKey(), entry.getValue());
          }
        } finally {
          pool.releaseJCas(jcas);
        }
      }
    }
  } catch (Exception e) {
    String logField = solrUIMAConfiguration.getLogField();
    if (logField == null) {
      SchemaField uniqueKeyField = cmd.getReq().getSchema()
          .getUniqueKeyField();
      if (uniqueKeyField != null) {
        logField = uniqueKeyField.getName();
      }
    }
    String optionalFieldInfo = logField == null ? "."
        : new StringBuilder(". ")
            .append(logField)
            .append("=")
            .append(
                (String) cmd.getSolrInputDocument().getField(logField)
                    .getValue()).append(", ").toString();
    int len;
    String debugString;
    if (text != null && text.length() > 0) {
      len = Math.min(text.length(), 100);
      debugString = new StringBuilder(" text=\"")
          .append(text.substring(0, len)).append("...\"").toString();
    } else {
      debugString = " null text";
    }
    if (solrUIMAConfiguration.isIgnoreErrors()) {
      log.warn(
          "skip the text processing due to {}",
          new StringBuilder().append(e.getLocalizedMessage())
              .append(optionalFieldInfo).append(debugString));
    } else {
      throw new SolrException(ErrorCode.SERVER_ERROR, new StringBuilder(
          "processing error ").append(e.getLocalizedMessage())
          .append(optionalFieldInfo).append(debugString).toString(), e);
    }
  }
  super.processAdd(cmd);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:72,代碼來源:UIMAUpdateRequestProcessor.java

示例7: processAdd

import org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField; //導入依賴的package包/類
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
  String text = null;
  try {
    /* get Solr document */
    SolrInputDocument solrInputDocument = cmd.getSolrInputDocument();

    /* get the fields to analyze */
    String[] texts = getTextsToAnalyze(solrInputDocument);
    for (int i = 0; i < texts.length; i++) {
      text = texts[i];
      if (text != null && text.length()>0) {
        /* process the text value */
        JCas jcas = processText(text);

        UIMAToSolrMapper uimaToSolrMapper = new UIMAToSolrMapper(solrInputDocument, jcas);
        /* get field mapping from config */
        Map<String, Map<String, MapField>> typesAndFeaturesFieldsMap = solrUIMAConfiguration
                .getTypesFeaturesFieldsMapping();
        /* map type features on fields */
        for (String typeFQN : typesAndFeaturesFieldsMap.keySet()) {
          uimaToSolrMapper.map(typeFQN, typesAndFeaturesFieldsMap.get(typeFQN));
        }
      }
    }
  } catch (Exception e) {
    String logField = solrUIMAConfiguration.getLogField();
    if(logField == null){
      SchemaField uniqueKeyField = solrCore.getSchema().getUniqueKeyField();
      if(uniqueKeyField != null){
        logField = uniqueKeyField.getName();
      }
    }
    String optionalFieldInfo = logField == null ? "." :
      new StringBuilder(". ").append(logField).append("=")
      .append((String)cmd.getSolrInputDocument().getField(logField).getValue())
      .append(", ").toString();
    int len;
    String debugString;
    if (text != null && text.length() > 0) {
      len = Math.min(text.length(), 100);
      debugString = new StringBuilder(" text=\"").append(text.substring(0, len)).append("...\"").toString();
    }
    else {
      debugString = " null text";
    }
    if (solrUIMAConfiguration.isIgnoreErrors()) {
      log.warn(new StringBuilder("skip the text processing due to ")
        .append(e.getLocalizedMessage()).append(optionalFieldInfo)
        .append(debugString).toString());
    } else {
      throw new SolrException(ErrorCode.SERVER_ERROR,
          new StringBuilder("processing error ")
            .append(e.getLocalizedMessage()).append(optionalFieldInfo)
            .append(debugString).toString(), e);
    }
  }
  super.processAdd(cmd);
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:60,代碼來源:UIMAUpdateRequestProcessor.java


注:本文中的org.apache.solr.uima.processor.SolrUIMAConfiguration.MapField類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。