odML to graphML converter.

Open
#175 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
databases

Research direction

No repository file or test is named. Start with the embedded Python example and inspect how odML conversion is exposed in this repository, including its ET.parse, Graph, and GraphMLParser entry points. Done means a supported odML-to-GraphML converter is integrated and usable for graph-database import.

Written by the indexing model from the issue text.

Description

graphML link is used in graphics community a lot. Here is a simple conversion code that can be used in odML. This would be helpful for importing odML to graph databases natively. Here is an example conversion that can be used as a basic starting point.

"""

 odml2graphml

 Basic odML to graphML converter

 (c) 2017 German Neuroinformatics Node (G-Node)

"""

import xml.etree.ElementTree as ET
from pygraphml import Graph
from pygraphml import GraphMLParser
import uuid

# Files
base_name     = 'rg_dummy'
odml_fname    = base_name + '.odml'
graphml_fname = base_name + '.graphml'

# Read odml
tree = ET.parse(odml_fname)
root = tree.getroot()

odml_graph            = Graph()
child_id              = 0
is_terminal_node_prev = False
prev_uuid_value       = 0
prev_node             = 0
is_odml_rel_node      = 0
prev_tag              = 'odML
for elem in tree.iter(): # iter over elements
    is_terminal_node = elem.getchildren() == []
    is_odml_tag      = elem.tag in ['section', 'odML', 'property']
    if(is_odml_tag):
        uuid_value          = str(uuid.uuid4()) # generate UUID for an element
        node                = odml_graph.add_node(uuid_value)
        node["odml_entity"] = elem.tag
        node["uuid"]        = uuid_value
        child_id            = 1
        is_odml_rel_node    = 0
        if(elem.tag == "odML"):
           odml_node = node
    else:
        node[elem.tag]        = elem.text
        node["labels"]        = ":reach2Grasp"
        is_terminal_node_prev = is_terminal_node
    if(is_odml_rel_node < 1 and child_id > 0 and is_odml_tag == True and prev_tag in ['section', 'property']):
       edge = odml_graph.add_edge(prev_node, node, directed=True)
       edge = odml_graph.add_edge(odml_node, node, directed=True)
       edge['relation'] = 'child'
    if(elem.tag in ['section', 'odML']):
       is_odml_rel_node   = 1
       prev_node          = node
       prev_uuid_value    = uuid_value
       prev_tag           = elem.tag
parser = GraphMLParser()
parser.write(odml_graph, graphml_fname)

Dominant language
Python
Stars
25
Forks
30
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from G-Node/python-odml

All issues in G-Node/python-odml

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.