DiffbotGraphTransformer#
- class langchain_experimental.graph_transformers.diffbot.DiffbotGraphTransformer(diffbot_api_key: str | None = None, fact_confidence_threshold: float = 0.7, include_qualifiers: bool = True, include_evidence: bool = True, simplified_schema: bool = True, extract_types: List[TypeOption] = [TypeOption.FACTS], *, include_confidence: bool = False)[source]#
Transform documents into graph documents using Diffbot NLP API.
A graph document transformation system takes a sequence of Documents and returns a sequence of Graph Documents.
Example
Initialize the graph transformer with various options.
- Parameters:
diffbot_api_key (str) β The API key for Diffbotβs NLP services.
fact_confidence_threshold (float) β Minimum confidence level for facts to be included.
include_qualifiers (bool) β Whether to include qualifiers in the relationships.
include_evidence (bool) β Whether to include evidence for the relationships.
simplified_schema (bool) β Whether to use a simplified schema for relationships.
extract_types (List[TypeOption]) β A list of data types to extract. Facts, entities, and sentiment are supported. By default, the option is set to facts. A fact represents a combination of source and target nodes with a relationship type.
include_confidence (bool) β Whether to include confidence scores on nodes and rels
Methods
__init__
([diffbot_api_key,Β ...])Initialize the graph transformer with various options.
convert_to_graph_documents
(documents)Convert a sequence of documents into graph documents.
nlp_request
(text)Make an API request to the Diffbot NLP endpoint.
process_response
(payload,Β document)Transform the Diffbot NLP response into a GraphDocument.
- __init__(diffbot_api_key: str | None = None, fact_confidence_threshold: float = 0.7, include_qualifiers: bool = True, include_evidence: bool = True, simplified_schema: bool = True, extract_types: List[TypeOption] = [TypeOption.FACTS], *, include_confidence: bool = False) None [source]#
Initialize the graph transformer with various options.
- Parameters:
diffbot_api_key (str) β The API key for Diffbotβs NLP services.
fact_confidence_threshold (float) β Minimum confidence level for facts to be included.
include_qualifiers (bool) β Whether to include qualifiers in the relationships.
include_evidence (bool) β Whether to include evidence for the relationships.
simplified_schema (bool) β Whether to use a simplified schema for relationships.
extract_types (List[TypeOption]) β A list of data types to extract. Facts, entities, and sentiment are supported. By default, the option is set to facts. A fact represents a combination of source and target nodes with a relationship type.
include_confidence (bool) β Whether to include confidence scores on nodes and rels
- Return type:
None
- convert_to_graph_documents(documents: Sequence[Document]) List[GraphDocument] [source]#
Convert a sequence of documents into graph documents.
- Parameters:
documents (Sequence[Document]) β The original documents.
kwargs β Additional keyword arguments.
- Returns:
The transformed documents as graphs.
- Return type:
Sequence[GraphDocument]
- nlp_request(text: str) Dict[str, Any] [source]#
Make an API request to the Diffbot NLP endpoint.
- Parameters:
text (str) β The text to be processed.
- Returns:
The JSON response from the API.
- Return type:
Dict[str, Any]
- process_response(payload: Dict[str, Any], document: Document) GraphDocument [source]#
Transform the Diffbot NLP response into a GraphDocument.
- Parameters:
payload (Dict[str, Any]) β The JSON response from Diffbotβs NLP API.
document (Document) β The original document.
- Returns:
The transformed document as a graph.
- Return type:
Examples using DiffbotGraphTransformer