Building a Knowledge Graph for Film and TV Characters: Data Structuring in Practice

    This article walks through a complete engineering approach for turning semi-structured film and TV person data—such as biographical entries mixing structured fields and long-form text—into a queryable, reasoning-ready knowledge graph. It covers ontology design, field and relation extraction, storage and query architecture, quality control, and typical applications such as question answering, recommendations, and search augmentation.

    In content and entertainment platforms, person-related data is among the most common and hardest types of data to govern. A typical film or TV biography mixes birth date, height, profession, filmography, and production details across both structured fields and long natural-language passages. Converting such semi-structured encyclopedia-style data into a knowledge graph that supports querying and reasoning is a frequent challenge for data engineers and backend developers. This article presents an end-to-end engineering solution centered on structuring film and TV person data.

    1. Problem Background: Why Person Data Is Hard to Use Directly

    Consider a typical encyclopedia entry for an actor. The raw data usually has these characteristics:

    1. Uneven information density: Core fields (name, birthday, nationality, profession) often occupy only a line or two, while filmographies, plot summaries, and award information take up the bulk of the text.
    2. Complex nested hierarchies: A TV series is not only the target of an “acted in” relation, but is itself an entity carrying dozens of attributes such as director, screenwriter, premiere date, episode count, ratings, and awards.
    3. Entity disambiguation difficulties: The same person may appear under different names across sources (for example, a foreign name alongside a translated name), and the same work may have multiple aliases. Matching purely on strings causes many incorrect associations.

    As a result, simple “field extraction + relational table storage” struggles to support multi-hop queries such as “actor → work → production team → awards.” Knowledge graphs are a natural fit for this kind of scenario.

    2. Data Modeling: Defining the Ontology

    The first step in modeling is to define the ontology: which entity types exist, what properties each type has, and which relations exist between entities. A reasonable design for the film and TV domain is:

    • Entity types: Person, Work, Award, Organization, Location.
    • Core relations: Person → acted in → Work; Person → directed → Work; Work → nominated for → Award; Work → filmed at → Location.
    • Property constraints: A person’s birthday must be a valid date, height must be a numeric value with a unit, and a work’s premiere date, episode count, and episode duration must have clearly defined data types.

    It is advisable to first codify these definitions using JSON Schema or a similar constraint description language, for example:

    1. {
    2. "entity": "Person",
    3. "properties": {
    4. "name_zh": {"type": "string", "required": true},
    5. "name_origin": {"type": "string"},
    6. "birthday": {"type": "string", "format": "date"},
    7. "height_cm": {"type": "number"},
    8. "profession": {"type": "array", "items": {"type": "string"}}
    9. },
    10. "relations": [
    11. {"name": "acted_in", "target": "Work", "since": "date"}
    12. ]
    13. }

    With a schema in place, downstream extraction, validation, and ingestion steps share a unified contract, preventing each module from going its own way.

    3. Extraction Pipeline: From Raw Text to Triples

    3.1 Structured Field Extraction

    Information such as birth date and height usually follows fixed patterns and can be captured with regular expressions or template matching:

    1. import re
    2. def extract_person_fields(text):
    3. birthday = re.search(r"(\d{4})年(\d{1,2})月(\d{1,2})日出生", text)
    4. height = re.search(r"身高\s*(\d+(?:\.\d+)?)\s*米", text)
    5. return {
    6. "birthday": "-".join(birthday.groups()) if birthday else None,
    7. "height_cm": float(height.group(1)) * 100 if height else None
    8. }

    3.2 Relation Extraction

    “Acted in” is the most important relation in this domain. In practice, it is common to combine rules with models:

    1. Rule layer: Recognize trigger phrases such as “filmography includes…” or “appeared in…”, then split candidate work titles by punctuation.
    2. Model layer: Use named entity recognition (NER) to distinguish work titles from person names, and use a relation classification model to determine the specific relation type between a person and a work (lead role, guest appearance, voice acting, etc.).
    3. Disambiguation layer: Align entities across sources using alias tables, release years, genres, and other multi-dimensional features, mapping all aliases of the same work to a single entity ID.

    3.3 Normalizing Complex Attributes

    Work-level information (premiere date, episode count, ratings, award records) is often scattered across long paragraphs and needs its own extraction pipeline, with unit and format normalization. For example, “60 minutes per episode” and “60min” from different sources should both be normalized to a standard minute count.

    4. Storage and Query Design

    There are two common technical routes for storing knowledge graphs:

    1. Graph databases: Nodes store entities and edges store relations, well suited for multi-hop queries such as “directors who have worked with a given actor more than twice.”
    2. Relational/document storage + graph layer: Keep core data in object storage or a document database, and redundantly store graph relations as adjacency lists—balancing cost and query flexibility.

    For small-to-medium-scale data, it makes sense to start with document storage plus inverted indexes to satisfy retrieval needs, then evolve to a dedicated graph store when multi-hop queries become a high-frequency requirement. If deploying in the cloud, you can combine the cloud provider’s managed database and object storage capabilities to reduce operational overhead.

    A typical multi-hop query (pseudocode):

    1. MATCH (p:Person)-[:acted_in]->(w:Work)<-[:directed]-(d:Person)
    2. WHERE p.name_zh = $name
    3. RETURN DISTINCT d.name_zh

    5. Quality Control and Continuous Updates

    Extraction results will never be 100% accurate, so a quality feedback loop is essential:

    • Validation rules: Hard constraints such as birth dates not being later than acting years, heights within reasonable ranges, and episode counts being positive integers.
    • Manual sampling review: Label and review low-confidence extraction results, and feed the results back into model iteration.
    • Incremental update mechanism: Encyclopedia-style data is revised continuously. Use “entity ID + content fingerprint” to decide whether re-extraction is needed, avoiding full recomputation.
    • Audit and lineage: Record the source and extraction time of every triple for traceability and conflict resolution.

    6. Typical Applications

    A structured person knowledge graph can directly support several business scenarios:

    1. Question answering: Answering natural-language questions such as “Which historical dramas has this actor appeared in?”
    2. Recommendations: Computing similarity based on the “actor–work–genre” graph structure to improve content recommendation relevance.
    3. Data dashboards: Analyzing actor collaboration networks and genre distributions to support content procurement and production decisions.
    4. Search augmentation: Presenting structured person cards and work relationship chains directly in search results.

    Conclusion

    Between a person entry that mixes natural language with fragmentary fields and a knowledge graph capable of multi-hop queries and reasoning lie five key stages: data modeling, entity extraction, relation recognition, storage design, and quality governance. In practice, it is advisable to start with a minimal viable schema and rule-based extraction for quick validation, then gradually introduce model capabilities and graph storage, letting the knowledge asset evolve together with the business.