This commit is contained in:
Diogo Cordeiro 2018-12-20 23:19:42 +00:00
commit 9fd09b6059
1 changed files with 20 additions and 5 deletions

View File

@ -33,6 +33,13 @@
*/
:- use_module(library(clpr)).
/*
* The porter_stem library implements the stemming algorithm described by
* Porter in Porter, 1980, ``An algorithm for suffix stripping''.
* The library also includes a functional tokenizer
*/
:- use_module(library(porter_stem)).
/*******************************
* NLP *
*******************************/
@ -48,10 +55,11 @@ polyplay :-
read_line_to_codes(user_input, InCodes),
%% Restore old prompt
prompt(_, OldPrompt),
%% Split the input at spaces and ignore \r and \t
split_string(InCodes, " ", "\r\t", LS),
%% Convert each set of codes into a term or atom, as appropriate
maplist(name, LA, LS),
%% Use the porter_stem library to tokenize the input
%% This does more than splitting at the spaces, such as
%% splitting at operators. Aditionally, gives
%% atoms already and handles 'P1' well
tokenize_atom(InCodes, LA),
(
%% If we read a 'bye', terminate
LA == [bye],
@ -310,6 +318,12 @@ print_all_stored_variables([]).
%
% Flatten a polynomail tree into a simple polynomial
%
polynomial_tree_to_polynomial(op(neg, T), P1) :-
%% If it matched on the version with a node, don't go back
!,
%% Delegate
polynomial_tree_to_polynomial(T, P),
atom_concat('-', P, P1).
polynomial_tree_to_polynomial(op(Op, TL, TR), P) :-
%% If it matched on the version with a node, don't go back
!,
@ -470,6 +484,7 @@ parse_floating_number(TN) -->
%@ TN = op('.', 2, 4).
%% ?- parse_floating_number(TN, [negative, two, dot, 4], _).
%@ TN = op('.', op(neg, 2), 4).
%@ TN = op('.', op(neg, 2), 4).
%% parse_positive_integer_number(-tree, +stream, -not_consumed) is det
%
@ -495,7 +510,7 @@ parse_integer_number(N) -->
parse_integer_number(op(neg, T)) --> % TODO
%% A number can start with "negative", to negate it
[negative],
parse_number_explicit(void, void, T).
parse_integer_number(T).
parse_integer_number(T) -->
parse_number_explicit(void, void, T).
%% Tests: