Subversion Repositories MeX

Compare Revisions

Ignore whitespace Rev 4 → Rev 3

/trunk/mex/services/srv_application.py
11,7 → 11,7
import uuid
from mex.core.mod_srv import Service
from mex.core.mod_env import GPATH, LPATH, APP, SEP
from mex.core.mod_rdf import BASE, URIRef, Literal
from mex.core.mod_rdf import BASE, ConjunctiveGraph, URIRef, NSBINDINGS, Literal
from pprint import pprint
 
 
41,8 → 41,6
 
repodict = {}
repoobjs = {}
samerank = ""
 
self.log.debug("Starting Metadata eXplorer")
self.srv_plugins = self.get_service('Plugins')
self.plugins = self.srv_plugins.get_plugins_by_category('Metadata')
50,6 → 48,10
fileset = self.srvutl.get_files_from_dir(params.SOURCE_PATH)
self.log.debug("Got %d files" % len(fileset))
 
graph = ConjunctiveGraph()
for ns in NSBINDINGS:
graph.bind(ns, NSBINDINGS[ns])
 
for path in fileset:
tuples = []
s = URIRef("%s%s" % (BASE, path))
56,7 → 58,6
rid = uuid.uuid4()
repodict[path] = {}
repodict[path]['uuid'] = str(rid)
samerank += "\"%s\"; " % rid
for plugin in self.plugins:
try:
metadata = plugin.plugin_object.get_metadata(self.app, path)
64,6 → 65,7
metadata = []
tuples.extend(metadata)
for p, o in tuples:
graph.add((s, p, o))
predicate = self.srvutl.pname(p)
if isinstance(o, URIRef) or isinstance(o, Literal):
o = str(self.srvutl.pname(o))
73,46 → 75,40
except:
repoobjs[o] = str(uuid.uuid4())
 
# Graph
output = "graph repository{\n"
output += " rankdir = LR;\n"
 
# Nodes
output = "graph graphname{\n"
nodes = []
relations = []
for path in fileset:
try:
node = " \"%s\" [shape=cylinder label=\"%s\" URL=\"file://%s\"]\n" % (repodict[path]['uuid'], repodict[path]['fileName'], path)
node = "\t\"%s\" [shape=cylinder label=\"%s\" URL=\"file://%s\"]\n" % (repodict[path]['uuid'], repodict[path]['fileName'], path)
output += node
nodes.append(node)
for prop in repodict[path]:
if prop not in ['uuid', 'fileName', 'fileUrl']:
pid = repoobjs[repodict[path][prop]]
node = " \"%s\" [label=\"%s\"]\n" % (pid, repodict[path][prop])
node = "\t\"%s\" [label=\"%s\"]\n" % (pid, repodict[path][prop])
nodes.append(node)
output += node
relation = " \"%s\" -- \"%s\" [label=\"%s\"]\n" % (repodict[path]['uuid'], repoobjs[repodict[path][prop]], prop)
relation = "\t\"%s\" -- \"%s\" [label=\"%s\"]\n" % (repodict[path]['uuid'], repoobjs[repodict[path][prop]], prop)
relations.append(relation)
except:
pass
 
# Same Rank
output += " {rank = same; %s}\n" % samerank
 
# Relations
for relation in relations:
output += relation
 
# End graph
output += "}"
 
with open(TARGET_PATH, 'w') as dot:
dot.write(output)
 
with open('mygraph.rdf', 'wb') as fout:
fout.write(graph.serialize(format='pretty-xml'))
self.log.debug("Generated dot file in: %s" % TARGET_PATH)
 
cmd = "circo -Tsvg %s > repository.html" % TARGET_PATH
self.log.debug("Execute command: %s" % cmd)
 
 
 
 
 
def end(self):
self.log.debug("Stopping Metadata eXplorer")
 
/trunk/Changelog
1,7 → 1,6
2019-09-01 Tomás Vírseda <tomasvirseda@gmail.com>
 
* First prototype built successfully
* Remove Conjunctive graph. Added Ranks
 
 
2019-08-31 Tomás Vírseda <tomasvirseda@gmail.com>