Skip to content

Commit

Permalink
modified to take filename from the command line
Browse files Browse the repository at this point in the history
svn/trunk@8508
  • Loading branch information
Ewan Klein committed Mar 10, 2010
1 parent 73fa8a0 commit b070750
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions nltk_contrib/rdf/rdfvizualize.py
@@ -1,3 +1,4 @@
#!/opt/local/bin/python
# Natural Language Toolkit: Generating RDF Triples from NL Relations
#
# Author: Ewan Klein <ewan@inf.ed.ac.uk>
Expand Down Expand Up @@ -31,7 +32,7 @@ def graph_options(self, uri, count):
self.options['color'] = 'green'

if isinstance(uri, BNode):
self.options['label'] = "_:bn%03d" % count
self.options['label'] = '"_:bn%03d"' % count


def graph2dot(self, filter_edges=False):
Expand Down Expand Up @@ -124,11 +125,11 @@ def serialize_demo():
except OSError:
print "Cannot read file '%s'" % FILE

def make_dot_demo():
def make_dot_demo(infile):
try:
store = ConjunctiveGraph()
store.parse(FILE, format='xml')
basename = FILE.split('.')[0]
store.parse(infile, format='xml')
basename = infile.split('.')[0]
v = Visualizer(store)
g = v.graph2dot(filter_edges=True)
g.write('%s.dot' % basename)
Expand All @@ -140,10 +141,19 @@ def make_dot_demo():
except OSError:
print "Cannot read file '%s'" % FILE


if __name__ == '__main__':
FILE = 'alice.rdf'


def main():
import sys
from optparse import OptionParser
description = \
"""
Turn an RDF file into a viewable graph using Graphviz.
"""
opts = OptionParser(description=description)
(options, args) = opts.parse_args()
if len(args) != 1:
parser.error("incorrect number of arguments")
infile = args[0]
#print
#print "Fill up a template and print out the resulting rdf in n3 format"
#print '*' * 30
Expand All @@ -154,15 +164,20 @@ def make_dot_demo():
#print '*' * 30
#write_rdf_demo()

print
print "Serialize some rdf in XML format"
print '*' * 30
serialize_demo()
#print
#print "Serialize some rdf in XML format"
#print '*' * 30
#serialize_demo()

print
print "Visualise an rdf graph with Graphviz"
print '*' * 30
make_dot_demo()
make_dot_demo(infile)

if __name__ == '__main__':
main()





Expand Down

0 comments on commit b070750

Please sign in to comment.