Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "edcgs"

Title:Extended Definite Clause Grammars
Rating:Not rated. Create the first rating!
Latest version:0.1.3
SHA1 sum:f0c3830b7dbc4b27cb8a691eabd0ab356a02739d
Author:Dietmar Seipel <seipel@informatik.uni-wuerzburg.de>
Falco Nogatz <fnogatz@gmail.com>
Maintainer:Falco Nogatz <fnogatz@gmail.com>
Packager:Falco Nogatz <fnogatz@gmail.com>
Home page:https://github.com/fnogatz/edcgs
Download URL:https://github.com/fnogatz/edcgs/releases/*.zip

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.1.00f32d97b20faa9def6a3e341fe8c80316b1752a01https://github.com/fnogatz/edcgs/archive/v0.1.0.zip
0.1.1ecd568a9fff252806fba57d72f7f42c7401aa9b21https://github.com/fnogatz/edcgs/archive/v0.1.1.zip
0.1.2bc42eabe61e11abb9bf6c62c186848a403fda6281https://github.com/fnogatz/edcgs/archive/v0.1.2.zip
0.1.3f0c3830b7dbc4b27cb8a691eabd0ab356a02739d4https://github.com/fnogatz/edcgs/archive/v0.1.3.zip

Extended DCGs

Extend Definite Clause Grammars (DCG) for Prolog by an additional argument to automatically store the parsing tree.

Synopsis

:- use_module(library(edcgs_expand)).

:- op(1200, xfx, ==>).

% Extended DCGs get expanded to hold additional
%   argument with syntax tree.
sentence ==> noun_phrase, verb_phrase.
noun_phrase ==> determiner, noun.
verb_phrase ==> ( verb ; verb, noun_phrase ).
noun ==> [boy] ; [boys] ; [apple] ; [apples].
determiner ==> [the].
verb ==> [eat].
verb ==> [eats].

main :-
  phrase(sentence(Tree), [the, boy, eats, the, apples]),
  print_term(Tree, [indent_arguments(2)]).

% prints:
%   sentence([
%     noun_phrase([
%       determiner(the),
%       noun(boy) ]),
%     verb_phrase([
%       verb(eats),
%       noun_phrase([
%         determiner(the),
%         noun(apples) ]) ]) ])

Installation

This pack is available from the add-on registry of SWI-Prolog.

It can be installed with pack_install/1:

?- pack_install(edcgs).

Requirements

Only for development purposes the tap pack is needed:

?- pack_install(tap).

Usage

In most cases you simply want to automatically expand all EDCGs to regular DCGs. To do so, simply call:

:- use_module(library(edcgs_expand)).
% and later the definition of EDCGs

Additionally you can manually call the predicates to translate an EDCG rule:

?- use_module(library(edcgs)).
?- edcg_rule_to_dcg_rule((sentence ==> noun_phrase, verb_phrase), DCG).
DCG = (sentence(X) --> ( ... )).

Contents of pack "edcgs"

Pack contains 8 files holding a total of 12.7K bytes.