### Installation Source: https://context7.com/alephdata/followthemoney/llms.txt Install the Follow the Money library using pip. ```APIDOC ## Installation ### Description Install the Follow the Money library using pip. ### Method `pip` ### Endpoint N/A ### Parameters None ### Request Example ```bash pip install followthemoney ``` ### Response N/A ``` -------------------------------- ### Install FollowTheMoney CLI Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Instructions for installing the ftm package via pip and verifying the installation. ```bash pip install followthemoney ftm --help ``` -------------------------------- ### Install Follow the Money Source: https://context7.com/alephdata/followthemoney/llms.txt Install the Python library using pip to begin working with the FtM toolkit. ```bash pip install followthemoney ``` -------------------------------- ### Model Entities and Relationships Source: https://context7.com/alephdata/followthemoney/llms.txt Provides examples of creating entities and defining relationships like Ownership using the FollowTheMoney schema model. ```python from followthemoney import model owner = model.make_entity('Person') company = model.make_entity('Company') ownership = model.make_entity('Ownership') ownership.add('owner', owner) ownership.add('asset', company) ``` -------------------------------- ### Install Profiling Dependencies Source: https://github.com/alephdata/followthemoney/blob/main/contrib/PERF.md Installs the necessary Python packages for performance analysis and visualization. SnakeViz is used for graphical representation of profile data. ```bash pip install snakeviz pycallgraph ``` -------------------------------- ### Python: Validate and Normalize Property Types Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates how to use the Follow the Money registry to access and validate various built-in property types like email, country, date, phone, and IBAN. It shows examples of cleaning and normalizing input data, with some types supporting fuzzy matching and country hinting. ```python from followthemoney.types import registry # Available property types print([t.name for t in registry.types]) # ['url', 'name', 'email', 'ip', 'address', 'date', 'phone', # 'country', 'language', 'mimetype', 'checksum', 'identifier', # 'iban', 'entity', 'topic', 'gender', 'json', 'text', 'html', # 'string', 'number'] # Type validation examples email_type = registry.email print(email_type.clean('John.Doe@EXAMPLE.COM')) # 'john.doe@example.com' print(email_type.clean('invalid')) # None country_type = registry.country print(country_type.clean('Germany', fuzzy=True)) # 'de' print(country_type.clean('DE')) # 'de' date_type = registry.date print(date_type.clean('2020-01-15')) # '2020-01-15' print(date_type.clean('15/01/2020', format='%d/%m/%Y')) # '2020-01-15' phone_type = registry.phone print(phone_type.clean('+1 (555) 123-4567')) # '+15551234567' print(phone_type.country_hint('+49301234567')) # 'de' ib an_type = registry.iban print(iban_type.clean('DE89 3704 0044 0532 0130 00')) # 'DE89370400440532013000' print(iban_type.country_hint('DE89370400440532013000')) # 'de' ``` -------------------------------- ### Define Unique Entity Keys Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx Demonstrates how to define unique keys for entities to prevent data collisions. The 'good.yml' example includes sufficient properties to uniquely identify a person. ```yaml entities: person: schema: Person keys: - FirstName - LastName - DoB properties: firstName: column: FirstName lastName: column: LastName birthDate: column: DoB ``` -------------------------------- ### Install ICU for Enhanced Transliteration Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Commands to install ICU dependencies on Debian-based Linux and macOS to improve transliteration support. ```bash # Debian-based apt install libicu-dev pip install pyicu # macOS brew install icu4c env CFLAGS=-I/usr/local/opt/icu4c/include env LDFLAGS=-L/usr/local/opt/icu4c/lib PATH=$PATH:/usr/local/opt/icu4c/bin pip install pyicu ``` -------------------------------- ### Map additional properties to a Person entity Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx This YAML example expands on the basic mapping by including additional properties such as email, alias, and a literal nationality value. ```yaml gb_parliament_57: queries: - csv_url: http://bit.ly/uk-mps-csv entities: member: schema: Person keys: - id properties: name: column: name alias: column: sort_name email: column: email nationality: literal: GB ``` -------------------------------- ### Entity Property Operations Source: https://context7.com/alephdata/followthemoney/llms.txt Perform operations on entity properties, including getting, checking, removing, and popping values. ```APIDOC ## Entity Property Operations ### Description Work with multi-valued properties and retrieve values by type. This includes getting all values, the first value, checking for existence, removing specific values, and popping all values. ### Method Python Script ### Endpoint N/A ### Parameters None ### Request Example ```python from followthemoney import model from followthemoney.types import registry entity = model.make_entity('Company') entity.id = 'acme-corp' entity.add('name', 'ACME Corporation') entity.add('name', 'ACME Corp.') # Multiple values allowed entity.add('jurisdiction', 'us') entity.add('registrationNumber', '12345678') entity.add('incorporationDate', '2020-01-15') # Get all values for a property names = entity.get('name') # ['ACME Corporation', 'ACME Corp.'] # Get first value only first_name = entity.first('name') # 'ACME Corporation' # Check if property has value has_name = entity.has('name') # True # Remove specific value entity.remove('name', 'ACME Corp.') # Pop all values from property all_names = entity.pop('name') # Returns and removes all values # Get all values by type across properties countries = entity.get_type_values(registry.country) identifiers = entity.get_type_values(registry.identifier) # Get caption (display name) for entity print(entity.caption) # 'ACME Corporation' # Get country hints (inferred from IBANs, phones, etc.) hints = entity.country_hints ``` ### Response N/A ``` -------------------------------- ### Manage Large Datasets with followthemoney-store Source: https://context7.com/alephdata/followthemoney/llms.txt Shows how to use the followthemoney-store for disk-based aggregation, including CLI commands for dataset management and Python code for bulk writing and iteration. ```bash cat fragments.json | ftm store write -d my_dataset ftm store iterate -d my_dataset > aggregated.json ``` ```python from ftmstore import get_dataset dataset = get_dataset('my_dataset', database_uri='sqlite:///data.db') bulk = dataset.bulk() for idx, entity in enumerate(generate_entities()): bulk.put(entity, fragment=idx) bulk.flush() ``` -------------------------------- ### Create and Manipulate Entities Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates how to instantiate entities, generate unique IDs, add validated properties, and serialize/deserialize data using the model singleton. ```python from followthemoney import model # Create a Person entity person = model.make_entity('Person') person.make_id('john-smith', '1979') person.add('name', 'John Smith') person.add('nationality', 'de') # Create a related Passport entity passport = model.make_entity('Passport') passport.make_id(person.id, 'C716818') passport.add('holder', person) # Serialize to dictionary data = person.to_dict() # Reconstruct entity from dictionary restored = model.get_proxy(data) ``` -------------------------------- ### Aggregate Entity Fragments via Python Library Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/fragments.mdx Shows how to use the followthemoney-store library in Python to programmatically ingest fragments, store them in a database, and retrieve merged entities. ```python import os from ftmstore import get_dataset from myapp.data import generate_fragments database_uri = os.environ.get('DATABASE_URI') dataset = get_dataset('myapp_dataset', database_uri=database_uri) bulk = dataset.bulk() for idx, proxy in enumerate(generate_fragments()): bulk.put(proxy, fragment=idx) bulk.flush() print(len(dataset)) for entity in dataset.iterate(): print(entity.caption) for proxy in dataset.partials(): print(proxy) entity = dataset.get(entity_id) ``` -------------------------------- ### Creating and Manipulating Entities Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates how to create, validate, and serialize entities using the Follow the Money model. ```APIDOC ## Creating and Manipulating Entities ### Description Create entity proxies using the model singleton to generate, validate, and serialize entity data. This includes adding properties, generating IDs, and linking entities. ### Method Python Script ### Endpoint N/A ### Parameters None ### Request Example ```python from followthemoney import model # Create a Person entity person = model.make_entity('Person') person.make_id('john-smith', '1979') # Generate unique ID from components person.add('name', 'John Smith') person.add('firstName', 'John') person.add('lastName', 'Smith') person.add('birthDate', '1979-08-23') person.add('nationality', 'de') # Values are validated - invalid country codes are rejected person.add('nationality', 'Atlantis') assert not person.has('nationality', 'Atlantis') # Fuzzy matching for country names person.add('nationality', 'Germany', fuzzy=True) print(person.first('nationality')) # Output: 'de' # Create a related Passport entity passport = model.make_entity('Passport') passport.make_id(person.id, 'C716818') passport.add('number', 'C716818') passport.add('holder', person) # Link to person entity # Serialize to dictionary for JSON storage data = person.to_dict() # { # "id": "a1b2c3...", # "schema": "Person", # "properties": { # "name": ["John Smith"], # "firstName": ["John"], # "lastName": ["Smith"], # "birthDate": ["1979-08-23"], # "nationality": ["de"] # } # } # Reconstruct entity from dictionary restored = model.get_proxy(data) assert restored == person ``` ### Response N/A ``` -------------------------------- ### Execute Data Mapping Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Commands to download a mapping file and generate FollowTheMoney entities from structured data. ```bash curl -o md_companies.yml https://raw.githubusercontent.com/alephdata/aleph/main/mappings/md_companies.yml ftm map md_companies.yml ``` -------------------------------- ### Advanced Property Mapping Configurations Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx Demonstrates how to handle complex data mapping scenarios including multi-column assignment, string concatenation, literal value assignment, and custom date formatting. These configurations are defined within the properties section of a FollowTheMoney mapping file. ```yaml properties: name: columns: - person_name - maiden_name name: columns: - first_name - last_name join: " " country: literal: "SS" birthDate: column: dob format: "%d.%m.%Y" ``` -------------------------------- ### Execute FollowTheMoney mapping via CLI Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx This command executes the defined YAML mapping file using the ftm command-line utility, outputting the resulting entities as JSON. ```bash ftm map brexitonians.yml ``` -------------------------------- ### Managing Entities and Schemas in Python Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/api.mdx Demonstrates how to load the model, access schema and property metadata, and perform CRUD-like operations on entity proxies. It covers ID generation, property assignment with validation, linking entities, and dictionary serialization. ```python from followthemoney import model from followthemoney.types import registry schema = model.get('Person') prop = schema.get('birthDate') assert prop.type == registry.date entity = model.make_entity(schema) entity.make_id('John Smith', '1979') entity.add(prop, '1979-08-23') entity.add('firstName', 'John') entity.add('lastName', 'Smith') entity.add('name', 'John Smith') entity.add('nationality', 'Germani', fuzzy=True) assert 'de' == entity.first('nationality') passport_entity = model.make_entity('Passport') passport_entity.make_id(entity.id, 'C716818') passport_entity.add('holder', entity) data = entity.to_dict() entity2 = model.get_proxy(data) assert entity2 == entity ``` -------------------------------- ### Export and load FollowTheMoney data into Neo4J Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Converts entity streams into Cypher commands and pipes them directly into a Neo4J instance using cypher-shell. ```bash curl -o us_ofac.ijson https://storage.googleapis.com/occrp-data-exports/us_ofac/us_ofac.json cat us_ofac.ijson | ftm export-cypher | cypher-shell -u user -p password ``` -------------------------------- ### Export Entity Streams via CLI Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates how to pipe entity JSON streams into various export formats including Excel, CSV, Neo4J, GEXF, and RDF using the ftm CLI tool. ```bash cat entities.json | ftm export-excel -o output.xlsx cat entities.json | ftm export-csv -o output_dir/ cat entities.json | ftm export-cypher | cypher-shell -u neo4j -p password cat entities.json | ftm export-gexf -o graph.gexf cat entities.json | ftm export-rdf > output.nt ``` -------------------------------- ### Python Library: ftmstore Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/fragments.mdx Using the followthemoney-store Python library to programmatically aggregate entity fragments. ```APIDOC ## Python Library: ftmstore ### Description Uses the ftmstore library to programmatically ingest entity fragments, perform aggregation, and retrieve merged entities from a database. ### Method Python API ### Endpoint ftmstore.get_dataset(dataset_name, database_uri) ### Parameters #### Request Body - **proxy** (EntityProxy) - Required - The entity fragment to be stored. - **fragment** (int) - Optional - A unique identifier for the fragment. ### Request Example bulk.put(proxy, fragment=idx) ### Response #### Success Response (200) - **dataset.iterate()** (generator) - Returns an iterator of fully merged EntityProxy objects. ``` -------------------------------- ### Export FollowTheMoney entities to CSV Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Uses the ftm CLI to split entity streams into multiple CSV files based on schema type within a target directory. ```bash curl -o us_ofac.ijson https://storage.googleapis.com/occrp-data-exports/us_ofac/us_ofac.json cat us_ofac.ijson | ftm validate | ftm export-csv -o OFAC/ ``` -------------------------------- ### Accessing Schema Metadata Source: https://context7.com/alephdata/followthemoney/llms.txt Learn how to introspect schema definitions and property types within the Follow the Money model. ```APIDOC ## Accessing Schema Metadata ### Description Introspect schemata and property types to understand entity structure. This includes retrieving schema details, listing properties, and checking schema inheritance. ### Method Python Script ### Endpoint N/A ### Parameters None ### Request Example ```python from followthemoney import model from followthemoney.types import registry # Get schema metadata schema = model.get('Person') print(schema.label) # 'Person' print(schema.plural) # 'People' # List all properties for prop in schema.sorted_properties: print(f"{prop.name}: {prop.type.name}") # name: name # birthDate: date # nationality: country # ... # Access property type information prop = schema.get('birthDate') assert prop.type == registry.date # Check schema inheritance company_schema = model.get('Company') print(company_schema.extends) # ['Organization', 'Asset'] print(company_schema.is_a('LegalEntity')) # True # Get all schemata with a specific property type country_schemata = model.get_type_schemata(registry.country) ``` ### Response N/A ``` -------------------------------- ### Export FollowTheMoney data to Neo4J bulk format Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Generates CSV files and a shell script for Neo4J database import. Requires the Neo4J server to be offline during the final import process. ```bash cat us_ofac.ijson | ftm export-neo4j-bulk -o folder_name -e iban -e entity -e address ``` -------------------------------- ### Aggregate Entity Fragments via CLI Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/fragments.mdx Demonstrates the command-line workflow for generating entity fragments from CSV data, storing them in a database, and iterating over the merged results. ```bash cat company-registry.csv | ftm map-csv mapping_file.yml > fragments.ijson cat fragments.ijson | ftm store write -d company_registry ftm store list ftm store iterate -d company_registry ``` -------------------------------- ### Export FollowTheMoney entities to Excel Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Uses the ftm CLI to convert an entity stream into a multi-sheet XLSX file. Requires a specified output file path. ```bash curl -o us_ofac.ijson https://storage.googleapis.com/occrp-data-exports/us_ofac/us_ofac.json cat us_ofac.ijson | ftm validate | ftm export-excel -o OFAC.xlsx ``` -------------------------------- ### Import Open Contracting Data Standard (OCDS) data Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Transforms OCDS JSON objects into FollowTheMoney Contract and ContractAward entities. Designed for datasets like OpenTender.eu. ```bash curl -o CY_ocds_data.json.tar.gz https://opentender.eu/data/files/CY_ocds_data.json.tar.gz tar xvfz CY_ocds_data.json.tar.gz cat CY_ocds_data.json | ftm import-ocds | ftm aggregate >cy_contracts.ijson ``` -------------------------------- ### Connect to SQL Database Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx Configures a mapping to load data from a PostgreSQL database using SQLAlchemy, including table aliasing and joins. ```yaml za_cipc: queries: - database: postgresql://localhost/cipc tables: - table: za_cipc_companies alias: companies - table: za_cipc_directors alias: directors joins: - left: companies.regno right: directors.company_regno ``` -------------------------------- ### CLI Entity Aggregation Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/fragments.mdx Demonstrates how to use the ftm CLI to map CSV data to fragments, store them in a database, and iterate over the aggregated entities. ```APIDOC ## CLI Entity Aggregation ### Description Processes entity fragments from a CSV source, stores them in a database table, and retrieves the merged, deduplicated entities. ### Method CLI Execution ### Endpoint ftm map-csv | ftm store write | ftm store iterate ### Parameters #### Path Parameters - **-d** (string) - Required - The name of the database table or dataset to store/retrieve fragments. ### Request Example cat company-registry.csv | ftm map-csv mapping_file.yml > fragments.ijson ### Response #### Success Response (200) - **entities** (json) - A stream of merged, complete entity objects. ``` -------------------------------- ### Define Event Keys Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx Shows how to link entities using a combination of keys from the participating entities for event schemas like Ownership. ```yaml entities: company: schema: Company keys: - company_name owner: schema: Person keys: - owner_name ownership: schema: Ownership keys: - company_name - owner_name ``` -------------------------------- ### Generate RDF Triples from Entities Source: https://context7.com/alephdata/followthemoney/llms.txt Shows how to serialize an entity into RDF triples using the FollowTheMoney model API. ```python from followthemoney import model entity = model.make_entity('Person') entity.add('name', 'John Smith') for subject, predicate, obj in entity.triples(): print(f"{subject} {predicate} {obj}") ``` -------------------------------- ### Managing Entity Fragments by Origin via CLI Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/fragments.mdx This snippet demonstrates how to write entity fragments to a store with specific origin tags, verify the count, and delete fragments associated with a particular origin. It uses the ftm command-line interface to interact with the sanctions dataset. ```bash cat us_ofac.ijson | ftm store write -d sanctions -o us_ofac cat eu_eeas.ijson | ftm store write -d sanctions -o eu_eeas # Will now have entities from both source files: ftm store iterate -d sanctions | wc -l # Delete all fragments from the second file: ftm store delete -d sanctions -o eu_eeas # Only one source file is left: ftm store iterate -d sanctions | wc -l ``` -------------------------------- ### Export FollowTheMoney data to RDF NTriples Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Transforms entity streams into RDF NTriples format, mapping properties to fully-qualified RDF predicates. ```bash curl -o us_ofac.ijson https://storage.googleapis.com/occrp-data-exports/us_ofac/us_ofac.json cat us_ofac.ijson | ftm validate | ftm export-rdf ``` -------------------------------- ### Export FollowTheMoney data to GEXF for Gephi Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Converts entity streams into GEXF format for network analysis in Gephi. Uses the -e flag to define which property types become graph nodes. ```bash curl -o us_ofac.ijson https://storage.googleapis.com/occrp-data-exports/us_ofac/us_ofac.json cat us_ofac.ijson | ftm validate | ftm export-gexf -e iban -o ofac.gexf ``` -------------------------------- ### Process Entity Streams in Python Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates efficient reading and writing of line-delimited JSON entity streams using orjson and the FollowTheMoney model. ```python import orjson from followthemoney import model def read_entities(input_file): with open(input_file, 'rb') as fh: for line in fh: data = orjson.loads(line) yield model.get_proxy(data) ``` -------------------------------- ### Map Moldovan Companies Data with Follow The Money Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx This YAML configuration defines how to map data from three CSV files (companies, directors, founders) into Follow The Money entities like Company, LegalEntity, Directorship, and Ownership. It specifies entity schemas, key identifiers, and property mappings, including relationships between entities. ```yaml md_companies: queries: - csv_url: http://assets.data.occrp.org/tools/aleph/fixtures/md_companies/companies.csv entities: company: schema: Company keys: - IDNO - Denumirea_completă properties: name: column: Denumirea_completă registrationNumber: column: IDNO incorporationDate: column: Data_înregistrării address: column: Adresa jurisdiction: literal: MD legalForm: column: Forma_org status: column: Statutul - csv_url: http://assets.data.occrp.org/tools/aleph/fixtures/md_companies/directors.csv entities: company: schema: Company keys: - Company_IDNO - Company_Name director: schema: LegalEntity keys: - Company_Name - Company_IDNO - Director properties: name: column: Director required: true directorship: schema: Directorship key_literal: Directorship keys: - Company_Name - Company_IDNO - Director properties: director: entity: director required: true organization: entity: company required: true role: literal: director - csv_url: http://assets.data.occrp.org/tools/aleph/fixtures/md_companies/founders.csv entities: company: schema: Company keys: - Company_IDNO - Company_Name founder: schema: LegalEntity keys: - Company_Name - Company_IDNO - Founder properties: name: column: Founder required: true ownership: schema: Ownership key_literal: Ownership keys: - Company_Name - Company_IDNO - Founder properties: owner: entity: founder required: true asset: entity: company required: true role: literal: founder ``` -------------------------------- ### Merge Entity Fragments Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates how to combine multiple entity fragments that share the same ID into a single consolidated entity. ```python from followthemoney import model fragment1 = model.make_entity('Person') fragment1.id = 'person-123' fragment1.add('name', 'John Smith') fragment2 = model.make_entity('Person') fragment2.id = 'person-123' fragment2.add('name', 'J. Smith') fragment2.add('nationality', 'de') ``` -------------------------------- ### Command-Line Data Processing Source: https://context7.com/alephdata/followthemoney/llms.txt Utilizes the ftm CLI tool to map, aggregate, validate, and pretty-print entity streams. ```bash ftm map mapping.yml > entities.json cat data.csv | ftm map-csv mapping.yml > entities.json ftm map mapping.yml | ftm aggregate > aggregated.json cat entities.json | ftm validate > clean.json cat entities.json | ftm pretty ``` -------------------------------- ### Profile Python Script Execution Source: https://github.com/alephdata/followthemoney/blob/main/contrib/PERF.md Executes a Python script with cProfile to generate a binary profile file, then launches SnakeViz to visualize the results. This helps identify functions consuming the most execution time. ```bash python -m cProfile -o benchmarch_prop.prof perf.py snakeviz benchmarch_prop.prof ``` -------------------------------- ### Perform Entity Property Operations Source: https://context7.com/alephdata/followthemoney/llms.txt Explains how to manage multi-valued properties, retrieve specific values, and extract metadata like captions and country hints from an entity. ```python from followthemoney import model from followthemoney.types import registry entity = model.make_entity('Company') entity.add('name', 'ACME Corporation') entity.add('name', 'ACME Corp.') # Get first value only first_name = entity.first('name') # Get all values by type across properties countries = entity.get_type_values(registry.country) # Get caption (display name) for entity print(entity.caption) ``` -------------------------------- ### Access Schema Metadata Source: https://context7.com/alephdata/followthemoney/llms.txt Shows how to introspect the schema model to retrieve labels, property types, inheritance hierarchies, and filter schemata by property type. ```python from followthemoney import model from followthemoney.types import registry # Get schema metadata schema = model.get('Person') # Check schema inheritance company_schema = model.get('Company') print(company_schema.is_a('LegalEntity')) # Get all schemata with a specific property type country_schemata = model.get_type_schemata(registry.country) ``` -------------------------------- ### Link entities using references Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/index.mdx Shows how to link two entities by storing the ID of one entity within the property of another, specifically using the entity reference type. ```json { "id": "passport-entity-id", "schema": "Passport", "properties": { "holder": ["person-entity-id"], "number": ["CJ 7261817"] } } ``` -------------------------------- ### Merge Entity Fragments Source: https://context7.com/alephdata/followthemoney/llms.txt Demonstrates how to merge two entity fragments into a single entity. The schema is automatically promoted to the most specific common type. ```python merged = fragment1.merge(fragment2) print(merged.get('name')) legal_entity = model.make_entity('LegalEntity') legal_entity.id = 'entity-456' legal_entity.add('name', 'Jane Doe') person = model.make_entity('Person') person.id = 'entity-456' person.add('birthDate', '1985-03-12') merged = legal_entity.merge(person) print(merged.schema.name) ``` -------------------------------- ### Perform Entity Aggregation Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Commands to map data and aggregate entity fragments into a single stream to resolve duplicate IDs. ```bash curl -o md_companies.yml https://raw.githubusercontent.com/alephdata/aleph/main/mappings/md_companies.yml ftm map md_companies.yml | ftm aggregate > moldova.ijson ``` -------------------------------- ### Define a basic Person entity mapping in YAML Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx This snippet demonstrates a simple YAML mapping file that pulls data from a CSV URL and maps it to a Person entity schema using a unique identifier and name column. ```yaml gb_parliament_57: queries: - csv_url: http://bit.ly/uk-mps-csv entities: member: schema: Person keys: - id properties: name: column: name ``` -------------------------------- ### Apply Namespace Signing Source: https://context7.com/alephdata/followthemoney/llms.txt Applies HMAC signatures to entity IDs to ensure dataset isolation. This allows for verifying and parsing signed IDs to maintain data integrity across references. ```python from followthemoney.namespace import Namespace ns = Namespace('my-dataset') signed = ns.apply(entity) print(signed.id) assert ns.verify(signed.id) plain_id, signature = Namespace.parse(signed.id) ``` -------------------------------- ### Map Local CSV Files Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Using ftm map-csv to process local CSV files by piping them into the mapping tool. ```bash cat people_of_interest.csv | ftm map-csv people_of_interest.yml | ftm aggregate ``` -------------------------------- ### Generate multiple entity types in one mapping Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx This YAML configuration demonstrates how to generate multiple entity types (Person and Organization) from a single source file, allowing for complex data relationships. ```yaml gb_parliament_57: queries: - csv_url: http://bit.ly/uk-mps-csv entities: member: schema: Person keys: - id properties: name: column: name party: schema: Organization keys: - group_id properties: name: column: group ``` -------------------------------- ### Define Membership Entity Relationship in Follow the Money YAML Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx This YAML mapping defines how to create a 'Membership' entity that links a 'Person' (member) to an 'Organization' (party). It uses temporary entity references ('member', 'party') to establish the relationship. The mapping assumes input data from a CSV file with columns for 'id', 'name', 'group_id', and 'group'. ```yaml gb_parliament_57: queries: - csv_url: http://bit.ly/uk-mps-csv entities: member: schema: Person keys: - id properties: name: column: name party: schema: Organization keys: - group_id properties: name: column: group membership: schema: Membership keys: - id - group_id properties: organization: entity: party member: entity: member ``` -------------------------------- ### Map Tabular Data to Entities Source: https://context7.com/alephdata/followthemoney/llms.txt Transforms CSV or SQL data into FtM entities using YAML mapping configurations. This can be done via YAML files or programmatically using the model. ```yaml dataset_name: queries: - csv_url: https://example.com/companies.csv entities: company: schema: Company properties: name: {column: company_name} ``` ```python from followthemoney import model mapping_config = {'queries': [{'csv_url': 'https://example.com/data.csv', 'entities': {...}}]} for entity in model.map_entities(mapping_config): print(entity.to_dict()) ``` -------------------------------- ### Reify property types for graph export Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Configures the Cypher exporter to treat specific property types as nodes, allowing for deeper network analysis. ```bash cat us_ofac.ijson | ftm export-cypher -e name -e iban -e entity -e address ``` -------------------------------- ### Define a basic Person entity Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/index.mdx Demonstrates the structure of a standard FtM entity, including a unique ID, schema type, and multi-valued properties. ```json { "id": "1b38214f88d139897bbd13eabde464043d84bbf9", "schema": "Person", "properties": { "name": ["John Doe"], "nationality": ["us", "au"], "birthDate": ["1982"] } } ``` -------------------------------- ### Compare Entity Similarity Source: https://context7.com/alephdata/followthemoney/llms.txt Calculates similarity scores between entities to assist in deduplication. It provides both an overall match score and detailed scores per property type. ```python from followthemoney.compare import compare, compare_scores score12 = compare(model, person1, person2) print(f"P1 vs P2: {score12:.2f}") scores = compare_scores(model, person1, person2) ``` -------------------------------- ### Create an interstitial entity for relationships Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/index.mdx Illustrates the use of an interstitial entity to define attributes for a relationship between two other entities, such as ownership details. ```json { "id": "ownership-entity-id", "schema": "Ownership", "properties": { "owner": ["person-entity-id"], "asset": ["company-entity-id"], "startDate": ["2020-01-01"], "percentage": ["51%"] } } ``` -------------------------------- ### Filter Source Data Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/mappings.mdx Applies equality filters to source data during the mapping process to import only specific subsets of records. ```yaml gb_parliament_57: queries: - csv_url: http://bit.ly/uk-mps-csv filters: group: 'Conservative' filters_not: gender: 'male' entities: member: schema: Person keys: - id properties: name: column: name ``` -------------------------------- ### Merging Entities Source: https://context7.com/alephdata/followthemoney/llms.txt Combine entity fragments that share the same ID into a single, consolidated entity. ```APIDOC ## Merging Entities ### Description Combine entity fragments that share the same ID into a single, consolidated entity. This is useful when data about the same entity is spread across multiple sources or documents. ### Method Python Script ### Endpoint N/A ### Parameters None ### Request Example ```python from followthemoney import model # First fragment with partial data fragment1 = model.make_entity('Person') fragment1.id = 'person-123' fragment1.add('name', 'John Smith') fragment1.add('birthDate', '1979-08-23') # Second fragment with additional data fragment2 = model.make_entity('Person') fragment2.id = 'person-123' fragment2.add('name', 'J. Smith') fragment2.add('nationality', 'de') fragment2.add('email', 'john@example.com') # To merge, you would typically load both fragments into the model # and the model would handle the consolidation based on ID. # Example of merging (conceptual): # model.merge_entities([fragment1, fragment2]) # merged_entity = model.get_proxy('person-123') ``` ### Response N/A ``` -------------------------------- ### Cleanup Neo4J graph data Source: https://github.com/alephdata/followthemoney/blob/main/docs/src/pages/docs/cli.mdx Cypher queries to remove unnecessary hierarchy relationships, isolated nodes, or to completely reset the database. ```cypher MATCH ()-[r:ANCESTORS]-() DELETE r; MATCH ()-[r:PARENT]-() DELETE r; MATCH (n:Page) DETACH DELETE n; MATCH (n:name) WHERE size((n)--()) <= 1 DETACH DELETE (n); MATCH (n:email) WHERE size((n)--()) <= 1 DETACH DELETE (n); MATCH (n:address) WHERE size((n)--()) <= 1 DETACH DELETE (n); MATCH (n) DETACH DELETE n; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.