comparison cpack/p2r/lib/README.md @ 0:718306e29690 tip

commiting public release
author Daniel Wolff
date Tue, 09 Feb 2016 21:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:718306e29690
1 # module uripattern
2
3 by Samer Abdallah, UCL, 2014
4
5
6 This directory contains several alternative implementations of a small URI grammar
7 which supports both generation and parsing (pattern-matching) of URIs.
8
9 There are two variants of the language. The earlier design is quite flexible but
10 leads to heavily non-deterministic parsing, which is perhaps not what one wants
11 for URI computations which might potentially be called very frequently. The later
12 design reduces or eliminates this non-determinism, depending on the implementatation.
13
14 ### Grammar
15
16 We describe the pattern grammar in terms of an algebraic datatype for the pattern language.
17
18
19 uri_pattern ---> prefix:uri_part
20 ; uri_part.
21
22 P :: prefix :- rdf_current_prefix(P). % any registered prefix atom
23 M :: macro_invocation :- uripattern:def(M,_).
24
25 uri_part ---> \macro_invocation
26 ; uri_part/uri_part % slash separated concatenation
27 ; uri_part+uri_part % direct concatenation
28 ; num(number) % decimal repn of number
29 ; enc(atomic) % HTML form-encoded atom
30 ; atm(atomic) % any atomic value
31 ; <any ground atom>
32 .
33
34 The more deterministic grammar removes direct concatenation and arbitrary atom parsing
35 but adds a tail/1 functor to capture all the remaining characters in the URI:
36
37 uri_part ---> \macro_invocation
38 ; uri_part/uri_part % slash separated concatenation
39 ; num(number) % decimal repn of number
40 ; enc(atomic) % HTML form-encoded atom
41 ; tail(atomic) % matches rest of URI
42 ; <any ground atom>
43 .
44
45 This grammar as written is not quite strict enough to enforce the rule that any tail/1
46 term must be the last thing in the pattern. The implementations are slightly less strict
47 than this this specification.
48
49
50 ### Example
51
52 Given the following declarations:
53
54 :- rdf_register_prefix(eg,'http://wwww.example.org/').
55 uripattern:def(matrix(X,Y),num(X)/num(Y)).
56
57 Then URIs can be generated as follows:
58
59 pattern_uri(eg:home,A).
60 ~> A='http://www.example.org/home'
61 pattern_uri(eg:files/tail('home/chomsky/.profile'),A).
62 ~> A='http://www.example.org/files/home/chomsky/.profile'
63 pattern_uri(eg:people/enc('Chomsky, N')/pets,A).
64 ~> A='http://www.example.org/people/Chomsky%2c%20N/pets'
65 pattern_uri(eg:chessboard/matrix(3,6),A).
66 ~> A='http://www.example.org/chessboard/3/6'
67
68 URIs can also be parsed, eg as follows
69
70 pattern_uri(eg:files/tail(Path), 'http://www.example.org/files/home/chomsky/.profile').
71 ~> Path=
72 pattern_uri(eg:people/enc(Name)/pets, 'http://www.example.org/people/Chomsky%2c%20N/pets').
73 ~> Name='Chomsky, N'
74 pattern_uri(eg:chessboard/matrix(X,Y), 'http://www.example.org/chessboard/3/6').
75 ~> X=3, Y=6
76
77
78 ### Implementations
79
80 There are several implementations:
81
82 uripattern\_constraint : Works by splicing atoms and uses delayed goals to handle arbitrary modes.
83
84 uripattern\_string : Works by splicing strings.
85
86 uripattern\_atom : Works by splicing atoms.
87
88 uripattern\_dcg : Converts URI to and from a list of codes and uses a DCG.
89
90 uripattern\_detdcg : A more deterministic DCG
91
92 uripattern\_detstring : A more deterministic version of string splicing.
93
94