Transform Spanish Legal Text into Structured Data with Law2Entity Cognitive Actions

22 Apr 2025
Transform Spanish Legal Text into Structured Data with Law2Entity Cognitive Actions

In the realm of legal technology, the ability to process and analyze legal texts efficiently is paramount. The Law2Entity Cognitive Actions offer developers a powerful toolset to convert complex Spanish legal texts into structured data formats. This integration aids in the development of knowledge graphs and enhances law entity recognition through fine-tuned prediction capabilities. By leveraging these pre-built actions, developers can significantly streamline the extraction of valuable insights from legal documents.

Prerequisites

Before you start using the Law2Entity Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with JSON format, as the input and output structures are based on JSON.
  • Basic understanding of making HTTP requests in your programming environment.

Authentication typically involves passing your API key in the request headers, allowing secure access to the Cognitive Actions service.

Cognitive Actions Overview

This action is designed to transform Spanish legal texts into structured data formats, aiding in the development of a knowledge graph. It utilizes advanced entity recognition techniques to identify and classify relevant legal entities.

Input

The input for this action requires the following fields:

  • input (string, required): The Spanish legal text that you want to process.
  • maxNewTokens (integer, optional): The maximum number of new tokens that can be generated. The default value is set to 5000.

Example Input:

{
  "input": "Morales no encuadran en la hipótesis legal a que se refiere el citado artículo 163 del Código Penal del Estado, ...",
  "maxNewTokens": 5000
}

Output

The output consists of structured data that includes:

  • entities: An array of identified entities, each with a name, type, and description.
  • relationships: An array describing the relationships between the identified entities.
  • claims: A list of claims derived from the input text, along with their status and time bounds.

Example Output:

{
  "entities": [
    {
      "entity_name": "Morales",
      "entity_type": "person",
      "entity_description": "Persona mencionada en el texto."
    },
    {
      "entity_name": "artículo 163 del Código Penal del Estado",
      "entity_type": "legal document",
      "entity_description": "Artículo del Código Penal del Estado mencionado en el texto."
    }
    // Additional entities...
  ],
  "relationships": [
    {
      "source_entity_name": "Morales",
      "target_entity_name": "artículo 163 del Código Penal del Estado",
      "relationship_type": "instance of",
      "relationship_description": "Morales no encuadran en la hipótesis legal a que se refiere el citado artículo 163 del Código Penal del Estado."
    }
    // Additional relationships...
  ],
  "claims": [
    {
      "claim_description": "Morales no encuadran en la hipótesis legal a que se refiere el citado artículo 163 del Código Penal del Estado.",
      "claim_status": "afirmado",
      "claim_time_bound": "presente"
    }
    // Additional claims...
  ]
}

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet demonstrating how to call the Law2Entity Cognitive Action to convert Spanish legal text into structured data:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "02343abf-5ed5-477f-88f0-3bdbbc29e663"  # Action ID for Convert Spanish Legal Text to Structured Data

# Construct the input payload based on the action's requirements
payload = {
    "input": "Morales no encuadran en la hipótesis legal a que se refiere el citado artículo 163 del Código Penal del Estado, ...",
    "maxNewTokens": 5000
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID corresponds to the Convert Spanish Legal Text to Structured Data action. The input payload is structured according to the action's schema, ensuring proper execution.

Conclusion

The Law2Entity Cognitive Actions provide developers with a robust means to extract structured insights from complex Spanish legal texts. By integrating these actions into your applications, you can facilitate the development of knowledge graphs and improve entity recognition in legal contexts. Consider exploring additional use cases, such as automating legal research or enhancing document analysis capabilities. Start harnessing the power of cognitive actions in your legal tech solutions today!