Demo entry 3300318

Test

   

Submitted by anonymous on Dec 09, 2015 at 20:08
Language: Prolog. Code size: 1.1 kB.

:- [read_line].



isValidDom(Dom) :-
	member(Dom,[a,every,the]).

isValidNoun(Noun) :-
	member(Noun, [bike,flight,person,train] ).

isValidVerb(Verb) :-
	member(Verb, [arrived,flew,left,stayed] ).

isValidPunc(Punc) :-
	member(Punc, [.]).


exportDCG(Line) :-
	[Dom,Noun,Verb,_] = Line,
	write('s(np(det('),
	write(Dom),
	write('),nom(noun('),
	write(Noun),
	write('))),vp(verb('),
	write(Verb),
	write(')))\n').

parse(Line) :-
	length(Line,4),
	[Dom,Noun,Verb,Punc] = Line,
	isValidDom(Dom),
	isValidNoun(Noun),
	isValidVerb(Verb),
	isValidPunc(Punc).
	
	%write(length(Line,5)).


loop :-
	read_line(Line),
	(parse(Line) -> exportDCG(Line); write('Invalid sentance\n')),
	loop.
	%parse(Line).

	%loop.


	/*
	?- loop.
	|: a train flew.
	s(np(det(a),nom(noun(train))),vp(verb(flew)))
	|: every train arrived.
	s(np(det(every),nom(noun(train))),vp(verb(arrived)))
*/

% Doms = [a,every,the]
% Nouns = [bike,flight,person,train]
% Verbs = [arrived,flew,left,stayed]

%( condition -> then_clause ; else_clause )

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).