Skip to main content

Converts RDF to GraphML suitable for yEd.

Project description

rdf2graphml

Python library for easy converting any RDF to GraphML (http://graphml.graphdrawing.org/specification/xsd.html) compatible with yEd (https://www.yworks.com/products/yed).

Note: This is work in progress!

Usage

rdf2graphml [-h] [-v] -c CONFIG OUTPUT INPUT [INPUT..] 

Configuration

The RDF-to-GraphML conversion is very customizable. The configuration can be supplied as JSON or Turtle file.

Example JSON Configuration

{
  "namespaces": {
    "ex": "http://example.org/ontology/"
  },
  "base_dir": "./icons",
  "icon_height": 64,
  "preferred_language": "en",
  "type_as_edge": false,
  "node_properties": [
    "http://www.w3.org/2000/01/rdf-schema#label"
  ],
  "icon_locators": [
    "http://example.org/ontology/iconUrl"
  ],
  "group_type": "http://example.org/ontology/Group",
  "group_contains": "http://example.org/ontology/contains",
  "default_node_style": {
    "blank_nodes": {
      "color": "#DDDDDD",
      "shape": "ellipse"
    },
    "uri_nodes": {
      "color": "#E8EEF7",
      "shape": "roundrectangle"
    }
  },
  "type_styles": {
    "http://example.org/ontology/System": {
      "icon": "system_icon.png",
      "color": "#ADD8E6",
      "shape": "roundrectangle",
      "priority": 10
    }
  },
  "edge_styles": {
    "http://example.org/ontology/dependsOn": {
      "color": "#FF0000",
      "line_type": "dashed",
      "target_arrow": "standard"
    }
  },
  "include_predicates": [
    "*"
  ],
  "exclude_predicates": []
}

Reference

General Settings

  • namespaces (object): A dictionary mapping prefixes to namespace URIs. These custom namespaces are registered with the converter to generate shorter QName labels (e.g., ex:Node) for nodes and edges instead of full URIs. Overrides existing prefixes in the source graph.
  • base_dir (string): The base directory used to resolve local image paths specified by icon_locators. Defaults to the directory of the configuration file.
  • icon_height (integer): The target height in pixels for downloaded/loaded icons. The width is scaled proportionally using Lanczos resampling. Default: 64.
  • preferred_language (string): The language tag used to pick the primary rdfs:label for display purposes (e.g., "en" or "de"). If not found, it falls back to a label without a language tag, or an arbitrary one. Default: "de".
  • type_as_edge (boolean): If true, rdf:type relations are drawn as explicit edges in the graph. If false, they are collected as node attributes (GraphML Data). Default: false.

RDF Mapping & Extraction

  • node_properties (list of strings): A list of URIs. Triples with these predicates are explicitly prevented from becoming edges. Instead, their objects are attached to the subject node as GraphML data attributes.
  • icon_locators (list of strings): A list of URIs. If a node has one of these predicates, the converter interprets the object as a URL or local file path to an image, downloads/reads it, converts it to Base64, and renders the node as a yEd ImageNode.

Groups & Hierarchies (Nested Graphs)

  • group_type (string): The URI of the rdf:type that identifies a node as a group container.
  • group_contains (string): The URI of the predicate used to link a group node to its children. These triples establish the nested graph hierarchy in yEd and will not be drawn as visible edges.

Styling

  • default_node_style (object): Fallback styling for nodes.

    • blank_nodes: Style object (color, shape) applied to RDF Blank Nodes. Default: Grey ellipse.
    • uri_nodes: Style object (color, shape) applied to standard URI nodes. Default: Light-blue roundrectangle.
  • type_styles (object): Maps rdf:type URIs to specific styles.

    • icon (string): URL or local path to a default image/icon for this type. Takes precedence over shape. If the image fails to load, the converter gracefully falls back to the configured shape.
    • color (string): Hex color code (e.g., "#ADD8E6").
    • shape (string): yEd shape identifier (e.g., "roundrectangle", "ellipse", "hexagon", "diamond").
    • priority (integer): If a node has multiple types, the style with the highest priority wins.
  • edge_styles (object): Maps predicate URIs to edge styles.

    • color (string): Hex color code.
    • line_type (string): Supported yEd line types (e.g., "line", "dashed", "dotted").
    • target_arrow (string): Supported yEd arrow types (e.g., "standard", "white_delta", "none").

RDF Lists

The converter automatically aggregates rdf:first/rdf:rest lists into a single node. You can style this generated node by targeting the URI https://www.hedenus.de/rdf2graphml/List.

  "type_styles": {
      "https://www.hedenus.de/rdf2graphml/List": {
          "color": "#FFD700",
          "shape": "hexagon",
          "priority": 100
    }}

Filtering

Filters accept Unix shell-style wildcards (e.g., * or http://example.org/*). The exclusion rules are always evaluated before the inclusion rules.

  • include_predicates (list of strings): Only predicates matching these patterns will be drawn as edges. If empty, all predicates (that are not structural/excluded) are allowed.
  • exclude_predicates (list of strings): Predicates matching these patterns are completely ignored.
  • include_types (list of strings): Only nodes possessing an rdf:type matching these patterns are drawn.
  • exclude_types (list of strings): Nodes possessing an rdf:type matching these patterns are explicitly ignored.

Styles known by yEd

shape:

  • diamond
  • ellipse
  • hexagon
  • octagon
  • parallelogram
  • rectangle
  • rectangle3d
  • roundrectangle
  • trapezoid
  • trapezoid2
  • triangle

line_type:

  • dashed
  • dashed_dotted
  • dotted
  • line

target_arrow:

  • diamond
  • none
  • standard
  • transparent_circle
  • white_delta

Example Turtle Configuration

@prefix conf: <https://www.hedenus.de/rdf2graphml/> .
@prefix ex: <http://example.org/ontology/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<#MyConverterConfig> a conf:Configuration ;
    
    # --- Custom Namespaces ---
    conf:namespace [
        conf:prefix "ex" ;
        conf:uri "http://example.org/ontology/"
    ] ;
    conf:namespace [
        conf:prefix "crm" ;
        conf:uri "http://www.cidoc-crm.org/cidoc-crm/"
    ] ;

    # --- General Settings ---
    conf:base_dir "./images" ;
    conf:icon_height 64 ;
    conf:preferred_language "en" ;
    conf:type_as_edge false ;
    
    # --- Hierarchy & Groups ---
    conf:group_type ex:Group ;
    conf:group_contains ex:contains ;

    # --- Lists (Using Turtle shorthand with 2 examples each) ---
    # Properties that should be converted to node attributes instead of edges
    conf:node_properties rdfs:label, ex:status ;
    
    # Properties that point to image URLs or local files for icons
    conf:icon_locators ex:iconUrl, ex:thumbnail ;
    
    # Predicate inclusion/exclusion filters (accepts wildcards)
    conf:include_predicates "*", "http://example.org/ontology/*" ;
    conf:exclude_predicates ex:internalSecretMetadata, ex:deprecatedProperty ;
    
    # Type inclusion/exclusion filters
    conf:include_types ex:System, ex:Person ;
    conf:exclude_types ex:DeprecatedNode, ex:HiddenNode ;

    # --- Default Fallback Styles ---
    conf:default_node_style [
        conf:blank_nodes [
            conf:color "#DDDDDD" ;
            conf:shape "ellipse"
        ] ;
        conf:uri_nodes [
            conf:color "#E8EEF7" ;
            conf:shape "roundrectangle"
        ]
    ] ;

    # --- Specific Node Type Styles ---
    # Using comma-separated blank nodes for multiple styles
    conf:type_styles [
        conf:target ex:System ;
        conf:color "#ADD8E6" ;
        conf:shape "roundrectangle" ;
        conf:icon "system_icon.png" ;
        conf:priority 10
    ],
    [
        conf:target ex:Person ;
        conf:color "#FFB6C1" ;
        conf:shape "ellipse" ;
        conf:priority 20
    ],
    [
        # Special target for the auto-generated RDF List wrapper node
        conf:target conf:List ;
        conf:color "#FFD700" ;
        conf:shape "hexagon" ;
        conf:priority 100
    ] ;
    
    # --- Specific Edge Styles ---
    conf:edge_styles [
        conf:target ex:dependsOn ;
        conf:color "#FF0000" ;
        conf:line_type "dashed" ;
        conf:target_arrow "standard"
    ],
    [
        conf:target ex:knows ;
        conf:color "#008000" ;
        conf:line_type "line" ;
        conf:target_arrow "none"
    ] .

Credits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rdf2graphml-0.4.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rdf2graphml-0.4.3-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file rdf2graphml-0.4.3.tar.gz.

File metadata

  • Download URL: rdf2graphml-0.4.3.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for rdf2graphml-0.4.3.tar.gz
Algorithm Hash digest
SHA256 13225fea61cc662ca4fa22baf5398dd50640539dff1ad161fe3e3e6846150ff8
MD5 bdc61604ffb22cdeb4433cc3607c04a7
BLAKE2b-256 f7b9a4603fda8004d3f8029ec6780f65afb586e77de99477b624c3e9d94319dd

See more details on using hashes here.

File details

Details for the file rdf2graphml-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: rdf2graphml-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for rdf2graphml-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 462c2bb74eacd49563d6b1bf9626920b888218efdaf1b056c71fe79736005a63
MD5 902d98f58372163fbfbb60b8c8922a1c
BLAKE2b-256 510c1257c15519ddf51380648c8ca5b966fc76a6babfb5151c53c1332c7b4a29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page