CS代考 :- use_module(library(readutil)).

:- use_module(library(readutil)).

/* As a Hokie, I, , will conduct myself with honor and integrity at all times.
I will not lie, cheat, or steal, nor will I accept the actions of those who do.”

Copyright By PowCoder代写 加微信 powcoder

Grammer parser and diagrammer

–>
–>
–> |
–>
–> definied in the Verbs list loaded via the definitions.pl
–> defined in the Adverbs list loaded via the definitions.pl
–> [] []
–> defined in the Nouns list loaded via the definitions.pl
–> |
–> defined in the Adjectives list loaded via the definitions.pl –> –> defined in the Prepostions list loaded via the definitions.pl

/* ==========================================================================================================================
Words we know are loaded using the consult. definition.pl is the file that is loaded in the consult.
*========================================================================================================================== */

make_go_now() :- consult(definitions), read_sentence(S).

/* ==========================================================================================================================
Reading Sentences from file
*========================================================================================================================== */
read_sentence(Sentence) :-
read_file_to_string(“input.txt”, Sentence1, []),
split_string(Sentence1,” \n”,”\n”,Sentence2),
convert_strings_to_atoms(Sentence2,[],Sentence),
parser(Sentence).

/* ==========================================================================================================================
Converting strings we read into atoms
*========================================================================================================================== */
convert_strings_to_atoms([],Sentence,Sentence).
convert_strings_to_atoms([Head|Tail],Builder,Sentence) :-
string_to_atom(Head,Atom),
append(Builder,[Atom],New_Builder),
convert_strings_to_atoms(Tail,New_Builder,Sentence).

/* ==========================================================================================================================
Parsing Sentence to make diagram
*========================================================================================================================== */

parser(Sentence) :-
verbs(Verbs),
nouns(Nouns),
prepositions(Prepositions),
adjectives(Adjectives),
adverbs(Adverbs),
tell(“output.txt”,Stream),
parse_sentence(Stream,Sentence,Diagram,[],Nouns,Verbs,Prepositions,Adjectives,Adverbs, subject),
close(Stream),!.

/* ==========================================================================================================================
Opening file for writing
*========================================================================================================================== */
tell(File,Stream) :- open(File,write, Stream).

/* ==========================================================================================================================
Printing list either console or given stream —
*========================================================================================================================== */
print_list([]).
print_list([Head|Tail]) :- write(” “),write(Head), write(” “), print_list(Tail).

print_list([],Stream):- nl(Stream).
print_list([Head|Tail],Stream) :- write(Stream,” “),write(Stream,Head), write(Stream,” “), print_list(Tail,Stream).

print_list_tail([]).
print_list_tail([Head|Tail]) :- print_list(Tail).

print_list_tail([], Stream):- nl(Stream).
print_list_tail([Head|Tail], Stream) :- write(Stream,” “), print_list(Tail, Stream).

/* ==========================================================================================================================
parse_sentenc currently contains a placeholder that writes the sentence after
removing the first word in the output.txt file.
You can modify any rule in this file as far as make_go_now() initiates the resolution process.
*========================================================================================================================== */
parse_sentence(Stream,Sentence,Diagram,[],Nouns,Verbs,Prepositions,Adjectives,Adverbs, subject) :-
print_list_tail(Sentence, Stream).

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com