コード例 #1
0
  @UsesExternalServices
  @Test
  public void testRequestIndependence() {
    @SuppressWarnings("unchecked")
    final Controller controller =
        ControllerFactory.createCachingPooling(org.carrot2.core.IDocumentSource.class);
    closeAfterTest(controller);

    final Map<String, Object> attrs = Maps.newHashMap();

    CommonAttributesDescriptor.attributeBuilder(attrs).results(50).query("data mining");

    controller.process(
        attrs, org.carrot2.webapp.source.WebDocumentSource.class, LingoClusteringAlgorithm.class);

    attrs.clear();
    CommonAttributesDescriptor.attributeBuilder(attrs)
        .results(50)
        .query(WebDocumentSource.QUERY_FAILURE);

    try {
      controller.process(
          attrs, org.carrot2.webapp.source.WebDocumentSource.class, LingoClusteringAlgorithm.class);
      fail();
    } catch (ProcessingException e) {
      assertThat(e.getCause().getMessage()).contains("Synthetic failure");
    }
  }
コード例 #2
0
 /**
  * Creates a new component configuration.
  *
  * @param componentClass the specific {@link IProcessingComponent} class.
  * @param componentId identifier of the component.
  * @param attributes initialization attributes for this component configuration.
  */
 public ProcessingComponentConfiguration(
     Class<? extends IProcessingComponent> componentClass,
     String componentId,
     Map<String, Object> attributes) {
   this.componentClass = componentClass;
   this.componentId = componentId;
   this.attributes = Collections.unmodifiableMap(Maps.newHashMap(attributes));
 }
コード例 #3
0
 static Map<String, ProcessingComponentConfiguration> indexByComponentId(
     ProcessingComponentConfiguration... configurations) {
   final HashMap<String, ProcessingComponentConfiguration> componentIdToConfiguration =
       Maps.newHashMapWithExpectedSize(configurations.length);
   for (ProcessingComponentConfiguration configuration : configurations) {
     if (componentIdToConfiguration.put(configuration.componentId, configuration) != null) {
       throw new IllegalArgumentException(
           "Duplicate processing component id: " + configuration.componentId);
     }
   }
   return Collections.unmodifiableMap(componentIdToConfiguration);
 }
コード例 #4
0
  @Test
  public void testXsltWithParameters() {
    IResource xml = resourceLocator.getFirst("/xml/custom-parameters-required.xml");
    IResource xslt = resourceLocator.getFirst("/xsl/custom-xslt.xsl");

    Map<String, String> xsltParameters = Maps.newHashMap();
    xsltParameters.put("id-field", "number");
    xsltParameters.put("title-field", "heading");
    xsltParameters.put("snippet-field", "snippet");
    xsltParameters.put("url-field", "url");

    processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xml"), xml);
    processingAttributes.put(AttributeUtils.getKey(XmlDocumentSource.class, "xslt"), xslt);
    processingAttributes.put(
        AttributeUtils.getKey(XmlDocumentSource.class, "xsltParameters"), xsltParameters);
    final int documentCount = runQuery();
    assertTransformedDocumentsEqual(documentCount);
  }
コード例 #5
0
  /** Reload all lexical resources associated with the given key. */
  private static HashMap<LanguageCode, ILexicalData> reloadResources(
      ResourceLookup resourceLookup) {
    // Load lexical resources.
    ObjectHashSet<MutableCharArray> mergedStopwords = new ObjectHashSet<>();
    ArrayList<Pattern> mergedStoplabels = Lists.newArrayList();

    HashMap<LanguageCode, ILexicalData> resourceMap = Maps.newHashMap();
    for (LanguageCode languageCode : LanguageCode.values()) {
      final String isoCode = languageCode.getIsoCode();

      ObjectHashSet<MutableCharArray> stopwords =
          toLower(load(resourceLookup, "stopwords." + isoCode));
      ArrayList<Pattern> stoplabels = compile(load(resourceLookup, "stoplabels." + isoCode));

      mergedStopwords.addAll(stopwords);
      mergedStoplabels.addAll(stoplabels);

      resourceMap.put(languageCode, new DefaultLexicalData(stopwords, stoplabels));
    }
    resourceMap.put(null, new DefaultLexicalData(mergedStopwords, mergedStoplabels));

    return resourceMap;
  }