当前位置: 首页>>代码示例>>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;未经允许,请勿转载。