-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfg.py
67 lines (56 loc) · 2.63 KB
/
cfg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
__author__ = "Antonio Masotti"
__date__ = "Jan 2021"
"""
DOC: Main file of the CFG-Parser
"""
from classes.parser import *
from pprint import pprint
import sys
import os
def ascii_logo():
print(""" _______ _______ _______
( ____ \( ____ \( ____ \
| ( \/| ( \/| ( \/
| | | (__ | |
| | | __) | | ____
| | | ( | | \_ )
| (____/\| ) | (___) |
(_______/|/ (_______)
_______ _______ _______ _______ _______ _______
( ____ )( ___ )( ____ )( ____ \( ____ \( ____ )
| ( )|| ( ) || ( )|| ( \/| ( \/| ( )|
| (____)|| (___) || (____)|| (_____ | (__ | (____)|
| _____)| ___ || __)(_____ )| __) | __)
| ( | ( ) || (\ ( ) || ( | (\ (
| ) | ) ( || ) \ \__/\____) || (____/\| ) \ \__
|/ |/ \||/ \__/\_______)(_______/|/ \__/
\n\n Welcome!""")
if __name__ == '__main__':
# Welcome
ascii_logo()
ARGUMENTS = sys.argv
################## WORK IN PROGRESS #####################################
## The following lines define some parameters just for testing sake
########################################################################
if len(ARGUMENTS) == 1: # no argument given --> test with default
GRAMMAR = os.path.abspath("data/rules_usami.txt")
SENTENCE = input('Give me a sentence: ')
print(f"Using {GRAMMAR} as testing path and '{SENTENCE}' as sentence.")
PARSER = Parser(GRAMMAR, SENTENCE)
PARSER.parse()
PARSER.to_tree(output=True, only_s=True, draw=True)
elif len(ARGUMENTS) == 3:
GRAMMAR = ARGUMENTS[1]
SENTENCE = ARGUMENTS[2]
GRAMMAR_TYPE = "as path for the grammar" if os.path.isfile(ARGUMENTS[1]) else "as grammar"
SENTENCE_TYPE = "as path for the sentence" if os.path.isfile(ARGUMENTS[2]) else "as sentence"
print(f"Using {GRAMMAR} {GRAMMAR_TYPE} and {SENTENCE} {SENTENCE_TYPE}.")
PARSER = Parser(GRAMMAR,SENTENCE)
PARSER.parse()
PARSER.to_tree(output=True,only_s=True,draw=True)
else:
print("""Usage:\n
python3 Parser.py <grammar file> <sentence file or string>\n
or
python3 Parser.py (with default params)\n
""")