Esempio n. 1
0
def __cli_parse__(args):
    """"""
    # validate IRI prefix
    # handle exceptions
    # handle invalid profile
    # handle output exceptions

    ts = itsdb.TestSuite(args.profile)
    prefix = args.prefix.strip("/")
    graph = Graph()

    for row in tsql.select('i-id i-input mrs', ts):
        id = row[0]
        text = row[1]
        if args.verbosity > 0:
            print("Parsing sentence {}".format(id))
        m = simplemrs.decode(row[2])
        # parse mrs from profile
        graph = p.mrs_to_rdf(m=m,
                             prefix=prefix,
                             identifier=id,
                             graph=graph,
                             text=text)
    # serializes output
    graph.serialize(destination=args.output, format=args.format)
Esempio n. 2
0
def __cli_parse__(args):
    """"""

    print(args)

    fmt = args.fmt
    path = args.path
    pref = args.prefix
    idtf = args.identifier

    # if a testsuite dir
    if not sys.stdin.isatty():
        input_text = sys.stdin.read()
    elif os.path.isdir(path):
        path = path.strip("/") + "/result.mrs"
        input_text = open(path, "r").read()

    if fmt == "simplemrs":
        m = simplemrs.decode(input_text)
        g = p.mrs_to_rdf(m, pref, idtf)
    elif fmt == "eds":
        pass
    elif fmt == "simpledmrs":
        pass
    # dmrsjson, dmrspenman, dmrx, edsjson, edspenman
    # indexedmrs, mrsjson, mrsprolog, mrx
    else:
        raise ValueError("No a valid format given")

    print(g.serialize(args.output, None))
Esempio n. 3
0
def __cli_parse__(args):
    """"""
    # validate IRI prefix
    # handle exceptions
    # handle invalid profile
    # handle output exceptions

    ts = itsdb.TestSuite(args.profile)
    prefix = args.prefix.strip("/")
    graph = Graph()

    for row in tsql.select('i-id i-input mrs', ts):
        id = row[0]
        text = row[1]
        m = simplemrs.decode(row[2])
        # parse mrs from profile
        p.mrs_to_rdf(m, prefix, id, graph, text=text)
    # serializes output
    graph.serialize(destination=args.output, format=args.format)
Esempio n. 4
0
from delphin import ace
from delphin import itsdb
from delphin import tsql
from delphin import dmrs, eds
from delphin.codecs import eds as edsnative
from delphin.codecs import simplemrs
from delphin.codecs import dmrx

# import parser as p
from delphin.rdf import parser as p
from rdflib import Graph
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("profile", help="profile path")
ts = itsdb.TestSuite(parser.parse_args().profile)
graph = Graph()
for row in tsql.select('i-id mrs', ts):
    m = simplemrs.decode(row[1])
    p.mrs_to_rdf(m, "http://example.com/example", row[0], graph)

graph.serialize(destination="test.ttl", format="turtle")