Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lml graph dump #2

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/abbreviations.xlsx
Binary file not shown.
10 changes: 7 additions & 3 deletions data/health_status_keywords_negative.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Breach,Alter,Incorrect,
Cessation,Regress ,Mistaken,
Disconnection,Decrease,Inaccurate,
Dissolution,Separate,Faulty,
Shock,(merge from verbs derived from noun list),Broken,
Tremor ,,Cracked,
Shock,harm,Broken,
Tremor ,(merge from verbs derived from noun list),Cracked,
Vibration,,Damaged,
Explosion,,Defective,
Termination,,Deficient ,
Expand Down Expand Up @@ -111,4 +111,8 @@ Interruption,,Blemished,
,,Exhausted,
,,Depleted,
,,Minimal,
,,Sparse,
,,Sparse,
,,inoperable,
,,unexpected,
,,unavailable,
,,neglected,
Binary file modified data/tag_keywords_lists.xlsx
Binary file not shown.
26 changes: 13 additions & 13 deletions others/tagKeywordListReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self,fileName):
Initialization method
Args:

fileName, string, file containing nuclear related entities
fileName, string, file containing nuclear related entities

Returns:

Expand All @@ -101,10 +101,10 @@ def __init__(self,fileName):
self.library = self.keyWordListGenerator(fileName)
self.cleanTagDict()
self.expander()

def checker(self):
"""
Method designed to check the structure of the set of nuclear related entities and identify entities
Method designed to check the structure of the set of nuclear related entities and identify entities
that might share multiple labels

Args:
Expand All @@ -120,7 +120,7 @@ def checker(self):
commonElements = list(set(self.library[key1]).intersection(self.library[key2]))
if key1!=key2 and commonElements:
print('Elements in common between ' +str(key1)+ ' and ' +str(key2)+ ' are:' + str(commonElements))

def getLibrary(self):
"""
Method designed to return self.library
Expand All @@ -134,7 +134,7 @@ def getLibrary(self):
self.library, dict, dictionary containing for each label a list of entities
"""
return self.library

def getAcronymsDict(self):
"""
Method designed to return self.acronymsDict
Expand All @@ -146,7 +146,7 @@ def getAcronymsDict(self):
Returns:

self.acronymsDict, dict, dictionary containing the acronyms contained in the library
"""
"""
return self.acronymsDict

def expander(self):
Expand All @@ -162,7 +162,7 @@ def expander(self):
Returns:

None
"""
"""
for key in self.library.keys():
for elem in self.library[key]:
if '-' in elem:
Expand All @@ -171,18 +171,18 @@ def expander(self):


def keyWordListGenerator(self, fileName):
"""
"""
Method designed to read the file and generate a dictionary which contains, for each tag,
the set of keywords that should be associate to such tag.

Args:

fileName, string, file containing nuclear related entities

Returns:

tagsDict, dict, dictionary containing for each label a list of entities
"""
"""

df = pd.read_excel(fileName, None)
# retrieve list of sheets in excel file
Expand All @@ -209,20 +209,20 @@ def keyWordListGenerator(self, fileName):


def cleanTagDict(self):
"""
"""
Method designed to clean the dictionary generated by the method keyWordListGenerator(.)
Here, specific characters or sub strings are removed.
In addition, if an acronym is defined (within round parentheses), then the acronyms_dict is
populated {acronym: acronym_definition}

Args:

None

Returns:

None
"""
"""

self.acronymsDict = {}
n_keywords = 0
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ dependencies = [
"jupyterlab",
"openpyxl",
"quantulum3",
"python>=3.9"
"python>=3.9",
"plotly",
"xlrd"
]
classifiers = [
"Programming Language :: Python :: 3",
Expand All @@ -41,4 +43,4 @@ classifiers = [
]

[project.urls]
"Homepage" = "https://github.inl.gov/congjian-wang/DACKAR"
"Homepage" = "https://github.com/idaholab/DACKAR"
69 changes: 47 additions & 22 deletions src/dackar/utils/mbse/LMLparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re
import networkx as nx
import pandas as pd
import graphdatascience as gds

class LMLobject(object):
"""
Expand Down Expand Up @@ -191,7 +192,7 @@ def returnGraph(self):

Returns:

self.LMLgraph: networkx object, graph containing entities specified in the LML MBSE model
self.LMLgraph: networkx object, graph containing entities specified in the LML model
"""
return self.LMLgraph

Expand Down Expand Up @@ -254,9 +255,39 @@ def cleanedGraph(self):

return self.cleanedGraph

def printOnFile(self, name, csv=True):
"""
This method is designed to print on file the graph from networkx.
This is to test a method to import a graph into neo4j as indicated in:
https://stackoverflow.com/questions/52210619/how-to-import-a-networkx-graph-to-neo4j
Args:

None

Returns:

def createNeo4jGraph(self):
None
"""
if csv:
name = name + ".csv"
nx.write_edgelist(self.LMLgraph, name, delimiter=',', data=True, encoding='utf-8')
else:
name = name + ".graphml"
nx.write_graphml(self.LMLgraph, name)


def dumpDGSgraph(self, name):
"""
This method is designed to save the graph structure into gds entity
See Example 3.2 in https://neo4j.com/docs/graph-data-science-client/current/graph-object/
Args:

None

Returns:

None
"""
NXnodes = list(self.LMLgraph.nodes(data=True))
NXedges = list(self.LMLgraph.edges)

Expand All @@ -273,7 +304,7 @@ def createNeo4jGraph(self):
nodes['nodeId'].append(index)
nodeInfo = node

mapping[node] = index
mapping[index] = node[0]

if nodeInfo[0] is None:
nodes['labels'].append(nodeInfo[1])
Expand All @@ -291,28 +322,23 @@ def createNeo4jGraph(self):

nodes = pd.DataFrame(nodes)

relationships = pd.DataFrame(
{
"sourceNodeId": [],
"targetNodeId": [],
"type": []
}
)
relationships = {
"sourceNodeId": [],
"targetNodeId": [],
"type" : []
}

for index,edge in enumerate(NXedges):
relationships['sourceNodeId'].append(mapping[edge[0]])
relationships['targetNodeId'].append(mapping[edge[1]])
father = [key for key, val in mapping.items() if val == edge[0]][0]
child = [key for key, val in mapping.items() if val == edge[1]][0]
relationships['sourceNodeId'].append(father)
relationships['targetNodeId'].append(child)
relationships['type'].append(edge[2])

'''
self.G = gds.graph.construct(
"my-graph", # Graph name
nodes, # One or more dataframes containing node data
relationships # One or more dataframes containing relationship data
)'''

return nodes, relationships
relationships = pd.DataFrame(relationships)

nodes.to_csv(name+'_nodes.csv')
relationships.to_csv(name+'_edges.csv')


def parseEntityDescription(text):
Expand All @@ -325,11 +351,10 @@ def parseEntityDescription(text):
text: str, text contained in the description node of the MBSE model

Returns:

out: tuple, tuple containing the list of elements specified in square brackets and separated
by commas (e.g., ['FV304,'305']) and the link to an external MBSE model
(e.g., ('centrifugalPumpFull', 'body'))

"""

if '[' in text:
Expand Down
54 changes: 37 additions & 17 deletions tests/LML_parser/LML_functionality_test.ipynb

Large diffs are not rendered by default.

Loading