pipeline
pipeline¶
- class hanlp.components.pipeline.Pipe(component: hanlp.common.component.Component, input_key: Optional[str] = None, output_key: Optional[str] = None, **kwargs)[source]¶
- static from_config(meta: dict, **kwargs)[source]¶
Build an object from config.
- Parameters
config – A
dict
holding parameters for its constructor. It has to contain a classpath key, which has a classpath str as its value.classpath
will determine the type of object being deserialized.kwargs – Arguments not used.
Returns: A deserialized object.
- predict(doc: hanlp_common.document.Document, **kwargs) hanlp_common.document.Document [source]¶
Predict on data. This is the base class for all components, including rule based and statistical ones.
- Parameters
*args – Any type of data subject to sub-classes
**kwargs – Additional arguments
Returns: Any predicted annotations.
- class hanlp.components.pipeline.Pipeline(*pipes: hanlp.components.pipeline.Pipe)[source]¶
- append(component: Callable, input_key: Optional[Union[str, Iterable[str]]] = None, output_key: Optional[Union[str, Iterable[str]]] = None, **kwargs)[source]¶
Append a pipe to the tail of this pipeline.
- Parameters
component – A callable function.
input_key – The input key indicating which fields will be inputted to the pipe.
None
: inherit from previous pipe;*
: use all the outputs from previous pipes wrapped in aDocument
.output_key – The output key indicating where to store the outputs
**kwargs – Extra arguments passed to the
Pipe
constructor.
- Returns
A pipeline.
- Return type
- static from_config(meta: Union[dict, str], **kwargs)[source]¶
Build an object from config.
- Parameters
config – A
dict
holding parameters for its constructor. It has to contain a classpath key, which has a classpath str as its value.classpath
will determine the type of object being deserialized.kwargs – Arguments not used.
Returns: A deserialized object.
- insert(index: int, component: Callable, input_key: Optional[Union[str, Iterable[str]]] = None, output_key: Optional[Union[str, Iterable[str]]] = None, **kwargs)[source]¶
- Parameters
index – The index of the new pipe.
input_key – The input key indicating which fields will be inputted to the pipe.
None
: inherit from previous pipe;*
: use all the outputs from previous pipes wrapped in aDocument
.output_key – The output key indicating where to store the outputs
**kwargs – Extra arguments passed to the
Pipe
constructor.
- Returns
A pipeline.
- Return type