org.carrot2.core
Class ProcessingResult

java.lang.Object
  extended by org.carrot2.core.ProcessingResult

public final class ProcessingResult
extends Object

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()).


Method Summary
static ProcessingResult deserialize(CharSequence input)
          Deserialize from an input stream of characters.
static ProcessingResult deserialize(InputStream input)
          Deserializes a ProcessingResult from an XML stream.
<T> T
getAttribute(String key)
          Returns a specific attribute of this result set.
 Map<String,Object> getAttributes()
          Returns attributes fed-in and collected during processing.
 List<Cluster> getClusters()
          Returns the clusters that have been created during processing.
 List<Document> getDocuments()
          Returns the documents that have been processed.
 String serialize()
          Serializes this ProcessingResult to an XML string.
 void serialize(OutputStream stream)
          Serializes this ProcessingResult to an XML stream.
 void serialize(OutputStream stream, boolean saveDocuments, boolean saveClusters)
          Serializes this ProcessingResult to a byte stream.
 void serialize(OutputStream stream, boolean saveDocuments, boolean saveClusters, boolean saveOtherAttributes)
          Serializes this ProcessingResult to a byte stream.
 void serializeJson(Writer writer)
          Serializes this processing result as JSON to the provided writer.
 void serializeJson(Writer writer, String callback)
          Serializes this processing result as JSON to the provided writer.
 void serializeJson(Writer writer, String callback, boolean saveDocuments, boolean saveClusters)
          Serializes this processing result as JSON to the provided writer.
 void serializeJson(Writer writer, String callback, boolean indent, boolean saveDocuments, boolean saveClusters)
          Serializes this processing result as JSON to the provided writer.
 void serializeJson(Writer writer, String callback, boolean indent, boolean saveDocuments, boolean saveClusters, boolean saveOtherAttributes)
          Serializes this processing result as JSON to the provided writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttributes

public Map<String,Object> getAttributes()
Returns attributes fed-in and collected during processing. The returned map is unmodifiable.

Returns:
attributes fed-in and collected during processing

getAttribute

public <T> T getAttribute(String key)
Returns a specific attribute of this result set. This method is equivalent to calling getAttributes() and then getting the required attribute from the map.

Parameters:
key - key of the attribute to return
Returns:
value of the attribute

getDocuments

public List<Document> getDocuments()
Returns the documents that have been processed. The returned collection is unmodifiable.

Returns:
documents that have been processed or null if no documents are present in the result.

getClusters

public List<Cluster> getClusters()
Returns the clusters that have been created during processing. The returned list is unmodifiable.

Returns:
clusters created during processing or null if no clusters were present in the result.

serialize

public String serialize()
Serializes this ProcessingResult to an XML string.


serialize

public void serialize(OutputStream stream)
               throws Exception
Serializes this ProcessingResult to an XML stream. The output includes all documents, clusters and other attributes.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
stream - the stream to serialize this ProcessingResult to. The stream will not be closed.
Throws:
Exception - in case of any problems with serialization

serialize

public void serialize(OutputStream stream,
                      boolean saveDocuments,
                      boolean saveClusters)
               throws Exception
Serializes this ProcessingResult to a byte stream. Documents and clusters can be included or skipped in the output as requested. Other attributes are always included.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
stream - the stream to serialize this ProcessingResult to. The stream will not be closed.
saveDocuments - if false, documents will not be serialized. Notice that when deserializing XML containing clusters but not documents, document references in Cluster.getDocuments() will not be restored.
saveClusters - if false, clusters will not be serialized
Throws:
Exception - in case of any problems with serialization

serialize

public void serialize(OutputStream stream,
                      boolean saveDocuments,
                      boolean saveClusters,
                      boolean saveOtherAttributes)
               throws Exception
Serializes this ProcessingResult to a byte stream. Documents, clusters and other attributes can be included or skipped in the output as requested.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
stream - the stream to serialize this ProcessingResult to. The stream will not be closed.
saveDocuments - if false, documents will not be serialized. Notice that when deserializing XML containing clusters but not documents, document references in Cluster.getDocuments() will not be restored.
saveClusters - if false, clusters will not be serialized
saveOtherAttributes - if false, other attributes will not be serialized
Throws:
Exception - in case of any problems with serialization

deserialize

public static ProcessingResult deserialize(CharSequence input)
                                    throws Exception
Deserialize from an input stream of characters.

Throws:
Exception

deserialize

public static ProcessingResult deserialize(InputStream input)
                                    throws Exception
Deserializes a ProcessingResult from an XML stream.

Parameters:
input - the input XML stream to deserialize a ProcessingResult from. The stream will not be closed.
Returns:
deserialized ProcessingResult
Throws:
Exception - is case of any problems with deserialization

serializeJson

public void serializeJson(Writer writer)
                   throws IOException
Serializes this processing result as JSON to the provided writer. The output includes all documents, clusters and other attributes.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
writer - the writer to serialize this processing result to. The writer will not be closed.
Throws:
IOException - in case of any problems with serialization

serializeJson

public void serializeJson(Writer writer,
                          String callback)
                   throws IOException
Serializes this processing result as JSON to the provided writer. The output includes all documents, clusters and other attributes.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
writer - the writer to serialize this processing result to. The writer will not be closed.
callback - JavaScript function name in which to wrap the JSON response or null.
Throws:
IOException - in case of any problems with serialization

serializeJson

public void serializeJson(Writer writer,
                          String callback,
                          boolean saveDocuments,
                          boolean saveClusters)
                   throws IOException
Serializes this processing result as JSON to the provided writer. Documents and clusters can be included or skipped in the output as requested. Other attributes are always included.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
writer - the writer to serialize this processing result to. The writer will not be closed.
callback - JavaScript function name in which to wrap the JSON response or null.
saveDocuments - if false, documents will not be serialized.
saveClusters - if false, clusters will not be serialized
Throws:
IOException - in case of any problems with serialization

serializeJson

public void serializeJson(Writer writer,
                          String callback,
                          boolean indent,
                          boolean saveDocuments,
                          boolean saveClusters)
                   throws IOException
Serializes this processing result as JSON to the provided writer.

This method is not thread-safe, external synchronization must be applied if needed.

Parameters:
writer - the writer to serialize this processing result to. The writer will not be closed.
callback - JavaScript function name in which to wrap the JSON response or null.
indent - if true, the output JSON will be pretty-printed
saveDocuments - if false, documents will not be serialized.
saveClusters - if false, clusters will not be serialized
Throws:
IOException - in case of any problems with serialization

serializeJson

public void serializeJson(Writer writer,
                          String callback,
                          boolean indent,
                          boolean saveDocuments,
                          boolean saveClusters,
                          boolean saveOtherAttributes)
                   throws IOException
Serializes this processing result as JSON to the provided writer. Documents, clusters and other attributes can be included or skipped in the output as requested.

Parameters:
writer - the writer to serialize this processing result to. The writer will not be closed.
callback - JavaScript function name in which to wrap the JSON response or null.
indent - if true, the output JSON will be pretty-printed
saveDocuments - if false, documents will not be serialized.
saveClusters - if false, clusters will not be serialized
saveOtherAttributes - if false, other attributes will not be serialized
Throws:
IOException - in case of any problems with serialization


Copyright (c) Dawid Weiss, Stanislaw Osinski