congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ProcessingResult
Code IndexAdd Tabnine to your IDE (free)

How to use
ProcessingResult
in
org.carrot2.core

Best Java code snippets using org.carrot2.core.ProcessingResult (Showing top 15 results out of 315)

origin: org.carrot2/carrot2-core

    xsltParameters);
query = (String) processingResult.getAttributes().get(AttributeNames.QUERY);
documents = processingResult.getDocuments();
  this.clusters = processingResult.getClusters();
origin: org.carrot2/carrot2-core

/**
 * Loads a {@link ProcessingResult} from the provided {@link InputStream}, applying
 * XSLT transform if specified. The provided {@link InputStream} will be closed.
 */
public ProcessingResult loadProcessingResult(InputStream xml, Templates stylesheet,
  Map<String, String> xsltParameters) throws Exception
{
  InputStream carrot2XmlStream = null;
  try
  {
    carrot2XmlStream = getCarrot2XmlStream(xml, stylesheet, xsltParameters);
    return ProcessingResult.deserialize(carrot2XmlStream);
  }
  finally
  {
    CloseableUtils.close(carrot2XmlStream, xml);
  }
}
origin: org.carrot2/carrot2-core

/**
 * Replace document refids with the actual references upon deserialization.
 */
private void documentIdToReference(Cluster cluster, Map<String, Document> documents)
{
  if (cluster.documentIds != null)
  {
    for (Cluster.DocumentRefid documentRefid : cluster.documentIds)
    {
      cluster.addDocuments(documents.get(documentRefid.refid));
    }
  }
  for (Cluster subcluster : cluster.getSubclusters())
  {
    documentIdToReference(subcluster, documents);
  }
}
origin: org.carrot2/carrot2-core

tempAttributes.put(AttributeNames.DOCUMENTS, getDocuments());
tempAttributes.put(AttributeNames.CLUSTERS, getClusters());
origin: medcl/elasticsearch-carrot2

{response.toXContent(builder, request);}
if (processingResult != null && processingResult.getClusters() != null) {
  final Collection<Cluster> clusters = processingResult.getClusters();
  final Map<String, Object> attributes = processingResult.getAttributes();
origin: org.dspace.dependencies.solr/dspace-solr-clustering

public Object cluster(Query query, DocList docList, SolrQueryRequest sreq) {
 try {
  // Prepare attributes for Carrot2 clustering call
  Map<String, Object> attributes = new HashMap<String, Object>();
  List<Document> documents = getDocuments(docList, query, sreq);
  attributes.put(AttributeNames.DOCUMENTS, documents);
  attributes.put(AttributeNames.QUERY, query.toString());
  // Pass extra overriding attributes from the request, if any
  extractCarrotAttributes(sreq.getParams(), attributes);
  // Perform clustering and convert to named list
  return clustersToNamedList(controller.process(attributes,
      clusteringAlgorithmClass).getClusters(), sreq.getParams());
 } catch (Exception e) {
  log.error("Carrot2 clustering failed", e);
  throw new RuntimeException(e);
 }
}
origin: org.carrot2/carrot2-core

    redirectStrategy);
final List<Document> documents = processingResult.getDocuments();
if (documents != null)
  final Map<String, Object> resultAttributes = processingResult.getAttributes();
  response.metadata
    .put(SearchEngineResponse.RESULTS_TOTAL_KEY, resultAttributes
origin: org.carrot2/carrot2-core

/**
 * Updates the statistics
 */
void update(ProcessingResult processingResult)
{
  synchronized (this)
  {
    totalQueries++;
    if (processingResult != null)
    {
      goodQueries++;
      final Map<String, Object> attributes = processingResult
        .getAttributes();
      addTimeToAverage(attributes, AttributeNames.PROCESSING_TIME_SOURCE,
        sourceTimeAverage);
      addTimeToAverage(attributes,
        AttributeNames.PROCESSING_TIME_ALGORITHM, algorithmTimeAverage);
      addTimeToAverage(attributes, AttributeNames.PROCESSING_TIME_TOTAL,
        totalTimeAverage);
    }
  }
}
origin: org.carrot2/carrot2-core

final Map<String, Object> attrs = prepareAttributesForSerialization(
  saveDocuments, saveClusters, saveOtherAttributes);
origin: org.carrot2/carrot2-core

  processingResult = new ProcessingResult(resultAttributes);
} catch (IllegalArgumentException e) {
  throw new ProcessingException(e);
origin: org.carrot2/carrot2-core

@Override
protected void afterFetch(SearchEngineResponse response,
  ProcessingResult processingResult)
{
  if (readClusters) {
    final Set<String> ids = Sets.newHashSet();
    List<Document> documents = processingResult.getDocuments();
    if (documents == null) documents = Collections.emptyList();
    List<Cluster> clusters = processingResult.getClusters();
    if (documents != null && clusters != null) {
      for (Document doc : documents) {
        ids.add(doc.getStringId());
      }

      Predicate<Document> docFilter = new Predicate<Document>()
      {
        @Override
        public boolean apply(Document input)
        {
          return input != null && ids.contains(input.getStringId());
        }
      };
      this.clusters = sanityCheck(clusters, docFilter);
    }
  }
}
origin: org.apache.solr/solr-clustering

@Override
public Object cluster(Query query, SolrDocumentList solrDocList,
  Map<SolrDocument, Integer> docIds, SolrQueryRequest sreq) {
 try {
  // Prepare attributes for Carrot2 clustering call
  Map<String, Object> attributes = new HashMap<>();
  List<Document> documents = getDocuments(solrDocList, docIds, query, sreq);
  attributes.put(AttributeNames.DOCUMENTS, documents);
  attributes.put(AttributeNames.QUERY, query.toString());

  // Pass the fields on which clustering runs.
  attributes.put("solrFieldNames", getFieldsForClustering(sreq));

  // Pass extra overriding attributes from the request, if any
  extractCarrotAttributes(sreq.getParams(), attributes);

  // Perform clustering and convert to an output structure of clusters.
  //
  // Carrot2 uses current thread's context class loader to get
  // certain classes (e.g. custom tokenizer/stemmer) at runtime.
  // To make sure classes from contrib JARs are available,
  // we swap the context class loader for the time of clustering.
  return withContextClassLoader(core.getResourceLoader().getClassLoader(),
    () -> clustersToNamedList(controller.process(attributes,
      clusteringAlgorithmClass).getClusters(), sreq.getParams()));
 } catch (Exception e) {
  log.error("Carrot2 clustering failed", e);
  throw new SolrException(ErrorCode.SERVER_ERROR, "Carrot2 clustering failed", e);
 }
}
origin: org.carrot2/carrot2-core

/**
 * Serializes this {@link ProcessingResult} to a byte stream. Documents, clusters and
 * other attributes can be included or skipped in the output as requested.
 * <p>
 * This method is not thread-safe, external synchronization must be applied if needed.
 * </p>
 * 
 * @param stream the stream to serialize this {@link ProcessingResult} to. The stream
 *            will <strong>not</strong> be closed.
 * @param saveDocuments if <code>false</code>, documents will not be serialized.
 *            Notice that when deserializing XML containing clusters but not
 *            documents, document references in {@link Cluster#getDocuments()} will
 *            not be restored.
 * @param saveClusters if <code>false</code>, clusters will not be serialized
 * @param saveOtherAttributes if <code>false</code>, other attributes will not be
 *            serialized
 * @throws Exception in case of any problems with serialization
 */
public void serialize(OutputStream stream, boolean saveDocuments,
  boolean saveClusters, boolean saveOtherAttributes) throws Exception
{
  final Map<String, Object> backupAttributes = attributes;
  attributes = prepareAttributesForSerialization(saveDocuments, saveClusters,
    saveOtherAttributes);
  new Persister().write(this, stream);
  attributes = backupAttributes;
}

origin: org.carrot2/carrot2-core

if (getDocuments() != null)
  documents = Lists.newArrayList(getDocuments());
if (getClusters() != null)
  clusters = Lists.newArrayList(getClusters());
origin: org.carrot2/carrot2-core

/**
 * Transfers document and cluster lists to the attributes map after deserialization.
 */
@Commit
private void afterDeserialization() throws Exception
{
  if (otherAttributesForSerialization != null)
  {
    attributes = SimpleXmlWrappers.unwrap(otherAttributesForSerialization);
  }
  attributesView = Collections.unmodifiableMap(attributes);
  attributes.put(AttributeNames.QUERY, query != null ? query.trim() : null);
  attributes.put(AttributeNames.DOCUMENTS, documents);
  attributes.put(AttributeNames.CLUSTERS, clusters);
  // Convert document ids to the actual references
  if (clusters != null && documents != null)
  {
    final Map<String, Document> documentsById = Maps.newHashMap();
    for (Document document : documents)
    {
      documentsById.put(document.getStringId(), document);
    }
    for (Cluster cluster : clusters)
    {
      documentIdToReference(cluster, documentsById);
    }
  }
}
org.carrot2.coreProcessingResult

Javadoc

Encapsulates the results of processing. Provides access to the values of attributes collected after processing and utility methods for obtaining processed documents ( #getDocuments())) and the created clusters ( #getClusters()).

Most used methods

  • getClusters
    Returns the clusters that have been created during processing. The returned list is unmodifiable.
  • getAttributes
    Returns attributes fed-in and collected during processing. The returned map is unmodifiable.
  • <init>
    Creates a ProcessingResult with the provided attributes. Assigns unique document identifiers if docu
  • deserialize
    Deserialize from an input stream of characters.
  • documentIdToReference
    Replace document refids with the actual references upon deserialization.
  • getDocuments
    Returns the documents that have been processed. The returned collection is unmodifiable.
  • prepareAttributesForSerialization
    Prepares a temporary attributes map for serialization purposes. Includes only the requested elements
  • serialize
    Serializes this ProcessingResult to a byte stream. Documents, clusters and other attributes can be i
  • serializeJson
    Serializes this processing result as JSON to the provided writer. Documents, clusters and other attr

Popular in Java

  • Running tasks concurrently on multiple threads
  • setRequestProperty (URLConnection)
  • addToBackStack (FragmentTransaction)
  • requestLocationUpdates (LocationManager)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • JList (javax.swing)
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now