module Lrepasa: sig .. end
Library of functions for repasa.
These sources are released to the public domain since 2002. No warranty.
Citation of the project Structio and the following URL is appreciated.
http://structio.sourceforge.net/repasa
type knownFormats =
| |
ForText |
| |
ForTexinfo |
| |
ForTeX |
| |
ForDocBook |
Handled formats in descriptions
val name_format : knownFormats -> string
val max : 'a -> 'a -> 'a
Returns the maximum between two data.
val gcmp : 'a -> 'a -> int
Comparision for List.sort and other functions.
Characters
val is_space : char -> bool
Decides if a character is a space.
val cmp_esp_char : bool -> string -> string -> int
cmp_esp_char case c1 c2 compares the spanish characters c1 and c2.
case : If false ignores differences between lower and uppercase.
Strings
val cmp_esp_str : bool -> string -> string -> int
cmp_esp_str case s1 s2 compares the strings s1 and s2.
case : If false ignores differences between lower and uppercase.
val last_char : string -> char
last_char s returns the last character of the string s.
val first_char : string -> char
first_char s returns the first character of the string s.
val str_to : string -> int -> string
str_to s i returns the prefix of s with i letters.
val str_from : string -> int -> string
str_from s i returns the postfix of s with i letters.
val str_isprefix : string -> string -> bool
str_isprefix s p decides if p is a prefix of s.
val str_split2 : string -> char -> string * string
str_split2 s c splits the string s that contains the character
c in two substrings, one before the separator c and the other
after it
val str_commprefix : string -> string -> string
str_commprefix s1 s2 returns the common prefix of s1 and s2.
val str_countchar : char -> string -> int
str_countchar c s returns the amount of times that the character c
appears in s.
val empty_string : string -> bool
empty_string s decides if the string s is empty
(i.e if it only has spaces).
val rep_string : string -> string -> string -> string
rep_string s x y Replaces the ocurrences of the string x in s
with y
val apply_str_conv : string -> string * string -> string
val split_string : string -> string -> string list
val compress_space : string -> string
compress_space s changes occurrences of multiple spaces in s for
just one.
val remove_extspace : string -> string
remove_extspace s Removes spaces at beginning and end of s.
val trim : string -> string
trim s Removes double space inside s as well as spaces at beginning
and end.
Special strings
val unescape_str : string -> string
unescape_str s Translate escape sequences in the string s to their
corresponding character. Uses the sequences:
\n End of line
\t Tabulator
\\ Backslash
val texinfo2txt : string -> string
texinfo2txt s Translates a string from a subset of Texinfo to simple
text.
Just some inline elements like @code, @email are translated
(see source code for details).
val txt2tex : string -> string
txt2tex s Translates the string s with pure text to plain TeX
val tex2txt : string -> string
tex2txt s Translates s from a subset of TeX to text.
Just some inline elements in math mode (e.g \alpha, \times) and
text mode (e.g \?`) are supported. See source code for details.
val char_to_xmlstr : char -> string
char_to_xmlstr c Returns the XML encoding of a character
val xml2txt : string -> string
xml2txt s substitutes in the xml string s some common entities
val atstr_from_str : string -> string
atstr_from_str s Translates the string s to an XML string
for an attribute
val xmlstr_from_str : string -> string
xmlstr_from_str s translates the string s to an XML PCDATA
Lists
val list_index : int -> 'a -> 'a list -> int
list_index 0 id l returns the index of id in the list l
(beginning numbering in 0) or -1 if it is not found
val list_left : int -> 'a list -> 'a list
list_left n l Return a list of the elements of l before position n.
The first position is 0.
val list_right : int -> 'a list -> 'a list
list_right n l Return a list of the elements of l after position n.
The first position is 0.
val random_perm_list : 'a list -> 'a list
random_perm_list l Permutes randomly a list
Hashing table
val hashtbl_first : ('a, 'b) Hashtbl.t -> ('a -> bool) -> 'a option
hashtbl_first h p Returns a key of the hashing table h that satisfies
the predicate p.
Returns If none exists returns None. If one exists returns Some k.
val hash_entries : ('a, 'b) Hashtbl.t -> int
hash_entries q returns the amount of different keys in the
hashing table q.
Option type
val valSome : 'a option -> 'a
valSome o returns the value of the option o.
o : Option, it must be Some x
Time
val sec_to_htime : int -> string
sec_to_htime s returns a string with time in seconds s converted
to minutes with affix m, or is still in seconds if s is less or equal
to 120
val check_date : int Pervasives.ref -> string -> string -> bool
check_date retval pos_file d Checks the string with date d, if a
problem ocurrs reports problem as appearing in pos_file and sets the
reference retval in a non-zero value.
Returns true iff the date is correct
retval : Puts 1 here if an error ocurrs.
pos_file : In case of error position to report.
d : Date to check. It can be a year, a month and a year or a
day a month and a year (in that order). Year, month and day can be
separated by spaces, '/', or '.'.
val extract_date : string -> int * int * int
extract_date d returns day, month and year of date in string d.
If it doesn't have day returns 0 as day, if it doesn't have month
return 0 as month, if the date is wrong (with respect to the
function check_date) throws and exception.
val get_date : 'a -> string
get_date () Returns a string with the local date in format
day/month/year
val days_date : string -> int
days_date d Returns the amount of days between 1, Jan, 1970 and
a given date d in the local time zone.
val file_basename : string -> string
file_basename n returns the name of the filename n (i.e removes
extension).
val file_extension : string -> string
file_extension n returns the extension of the filename n.
Trees of the markup library
val exemplar_element : ('a Markup_document.node Markup_document.extension as 'a)
Markup_document.element_impl
Examplar to create a new element
val exemplar_data : ('a Markup_document.node Markup_document.extension as 'a)
Markup_document.data_impl
Examplar to create a data node
val add_markup_path : string -> unit
add_markup_path path If it doesn't exists adds the path path
to the paths where XMLs and DTDs opened by Markup are looked for
(with higher priority than exisiting entries
val empty_root_data : < data : string; node_type : Markup_document.node_type; .. > list -> bool
empty_root_data l Decides if the nodes in the markup-forest l
don't have data.
val count_root_elem : string -> < node_type : Markup_document.node_type; .. > list -> int
count_root_elem name l returns the amount of root elements with name name
in the markup-forest l.
val has_attr : < attribute : 'a -> Markup_types.att_value; .. > -> 'a -> bool
has_attr elem name decides if the element elem has an attribute
name.
val attr : < attribute : string -> Markup_types.att_value; .. > -> string -> string
attr elem name returns the attribute name of the element elem.
val name_element : < node_type : Markup_document.node_type; .. > -> string
name_element elem returns the name of the element elem.
val count_root_elem_attr : string ->
string ->
string ->
(< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type; sub_nodes : 'a; .. >
list as 'a) ->
int
count_root_elem_attr lab_elem lab_attr val_attr l returns the amount
of root elements in markup-forest l with the label lab_elem, with the
attribute lab_attr and the value val_attr for the attribute.
val count_elem_pred : (string ->
(< node_type : Markup_document.node_type; sub_nodes : 'a list; .. > as 'a) ->
bool) ->
'a list -> int
count_elem_pred pred l returns the amount of elements in markup-forest
l that satisfy the predicate pred.
val count_roots : < node_type : Markup_document.node_type; .. > list -> int
count_roots l count the amount of root elements in the markup-forest
l. *
val extract_data : < data : string; node_type : Markup_document.node_type; .. > list -> string
extract_dat l Extracts all the data of the markup-forest l.
val filter_elem : ((< node_type : Markup_document.node_type; .. > as 'a) -> bool) ->
'a list -> 'a list
filter_elem p l Filters all the elements of markup-forest l that
satisfy predicate p, withouth looking subnodes.
val first_elem : (string -> (< node_type : Markup_document.node_type; .. > as 'a) -> bool) ->
'a list -> 'a option
first_elem p l Returns the first element in the markup-forest l
that fulfills the predicate p withouth looking subnodes
val first_deep_nelem : string ->
((< node_type : Markup_document.node_type; sub_nodes : 'a list; .. > as 'a) ->
bool) ->
'a list -> 'a option
first_deep_nelem n p l returns the first element with name
n from forest l that fulfills predicate p.
Looks first in brothers then in sons.
val exists_elem : (string -> (< node_type : Markup_document.node_type; .. > as 'a) -> bool) ->
'a list -> bool
exists_elem p l returns true if there is an element in the markup-forest
l that fulfills the predicate p withouth looking subnodes
val exists_deep_nelem : string ->
((< node_type : Markup_document.node_type; sub_nodes : 'a list; .. > as 'a) ->
bool) ->
'a list -> bool
exists_deep_nelem n p l returns true if there is an element with
name n in any branch of the markup-forest l that fulfills the
predicate p. Looks first for brothers then in sons.
val iter_elem : (string ->
(< node_type : Markup_document.node_type; sub_nodes : 'a list; .. > as 'a) ->
'b) ->
'a list -> unit
iter_elem f l Iterates over all the elements of a markup-forest l
applying the function f. Applies the function to each node, then
to its brothers, then to its sons.
val iter_nelem : string ->
((< node_type : Markup_document.node_type; sub_nodes : 'a list; .. > as 'a) ->
unit) ->
'a list -> unit
iter_nelem n f le Iterates over all the elements of the
markup forest le with the given name n,
applying function f.
Applies the function to each node, then to its brothers, then to its sons.
val filter_elem_pname : (string -> bool) ->
(< node_type : Markup_document.node_type; .. > as 'a) list -> 'a list
filter_elem_pname pred l Extracts all the elements in the
markup-forest l whose name satisfy the predicate pred
(it doesn't look in sub nodes).
Returns Sublist of l with nodes that satisfy pred
val ppr_markup : Pervasives.out_channel ->
< dtd : < write_compact_as_latin1 : Markup_types.output_stream ->
bool -> unit;
.. >;
root : < attributes : (string * Markup_types.att_value) list;
data : string; dtd : < id : Markup_types.dtd_id option; .. >;
node_type : Markup_document.node_type; sub_nodes : 'a list; .. >
as 'a;
.. > ->
unit
ppr_markup oc t Pretty prints the Markup tree t as XML (it doesn't use
included DTDs).
DTDs of repasa
val check_bib : int Pervasives.ref ->
< pos_file : string;
sub_nodes : < data : string; node_type : Markup_document.node_type; .. >
list;
.. > ->
unit
check_bib retval elem checks the bibliography node elem.
retval : Puts 1 here if an error ocurrs.
elem : Element to check
val check_rights : int Pervasives.ref ->
< attribute : string -> Markup_types.att_value; pos_file : string;
sub_nodes : < data : string; node_type : Markup_document.node_type; .. >
list;
.. > ->
unit
check_rights retval elem Checks node with rights elem.
retval : Puts 1 here if an error ocurrs.
elem : Element to check
val check_author : int Pervasives.ref ->
< attribute : string -> Markup_types.att_value; pos_file : string;
sub_nodes : < data : string; node_type : Markup_document.node_type; .. >
list;
.. > ->
unit
check_author retval elem Checks node with an author name elem.
retval : Puts 1 here if an error ocurrs.
elem : Element to check
val check_annotation : int Pervasives.ref ->
(string * string, string) Hashtbl.t ->
< attribute : string -> Markup_types.att_value; pos_file : string; .. > ->
unit
check_annotation retval hat elem Checks node elem with an annotation,
uses hat to check repeated annotations.
retval : Puts 1 here if an error ocurrs.
val extract_desc : < node_type : Markup_document.node_type;
sub_nodes : < data : string; node_type : Markup_document.node_type; .. >
list;
.. >
list -> string
extract_desc l extracts data of an element <desc> in the
markup-forest l.
Types and identifications in some files
val check_id : string ->
int ->
(string, string) Hashtbl.t ->
int Pervasives.ref ->
< attribute : string -> Markup_types.att_value; pos_file : string; .. > ->
unit
check_id idparent numdot hi retval elem
decides if the element elem with id and type has appropiate id and type.
idparent : Identification of parent node
numdot : Amount of dots that the identification must have
hi : Hashing table with (identification) -> pos
retval : Puts 1 here if an error ocurrs.
elem : Element to check. If it has attribute "type" this function
checks that its value doesn't contain ;
val check_type_hier : bool ->
(string * string, string) Hashtbl.t ->
int Pervasives.ref ->
bool ->
string list ->
< attribute : string -> Markup_types.att_value; pos_file : string; .. > ->
string -> unit
check_type_hier chkord hc retval strict hiertypes elem parent_type
decides if the element elem with id and type has appropiate id and type.
hc : Hashing table with (type,identification) -> pos
retval : Puts 1 here if an error ocurrs.
strict : when true the order is checked strictly and errors
are generated. When false warnings are generated.
hiertypes : order of types (list)
parent_type : Last type read in a parent node
val check_common : int Pervasives.ref ->
int Pervasives.ref ->
int Pervasives.ref ->
int Pervasives.ref ->
int Pervasives.ref ->
(string * string, string) Hashtbl.t ->
< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type; pos_file : string;
sub_nodes : < data : string; node_type : Markup_document.node_type; .. >
list;
.. > ->
unit
check_common retval bib rights authors annot elem Checks common
elements to several, this must be the last after checking others
type heuresp =
| |
HCaseSensitive |
| |
HCaseInsensitive |
Types of heuristics to test answers
val test_equal_answer : heuresp -> string -> string -> bool
test_equal_answer heur w ans tests if the answer ans is equal to
the word w by using the heuristics heur.
val parse_heur : < attribute : string -> Markup_types.att_value; pos_file : string; .. > ->
heuresp
parse_heur elem
Definitions
val extract_meaning_tree : string ->
< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type;
sub_nodes : (< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type; .. >
as 'a)
list;
.. >
list -> string * 'a list
extract_meaning_tree id l extracts tree with meaning with
id id from the definitions tree l (def.dtd).
Returns None if the data is not found or Some tree_node otherwise.
id : Id of the meaning (must have .).
l : List of nodes of a markup tree.
val extract_meaning : string ->
< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type;
sub_nodes : < attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type;
sub_nodes : < data : string;
node_type : Markup_document.node_type; .. >
list;
.. >
list;
.. >
list -> string option
extract_meaning id l extracts meaning with id idm
from the definitions tree l (def.dtd).
Returns None if the data is not found or Some meaning otherwise.
id : Id of the meaning. Must have '.'
l : List of nodes of a markup tree.
val extract_meaning_badchoices : string ->
< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type;
sub_nodes : < attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type; pos_file : string;
sub_nodes : < data : string;
node_type : Markup_document.node_type; .. >
list;
.. >
list;
.. >
list ->
(string * heuresp * string * string list * string list) option
extract_meaning_badchoices id l Extracts meaning with idm and
bad choices for it from the definitions tree l
Returns None if the data is not found or
Some(word,meaning,listdespiste,listpista) otherwise.
id : Id of the meaning. Must have '.'
l : List of nodes of a markup tree.
val extract_meaning_file : int Pervasives.ref ->
string ->
string ->
('a Markup_document.extension Markup_document.node as 'a) list ->
string -> string -> string option
extract_meaning_file retval pos_file dname defs fname id Extracts
a meaning opening the necessary files or using the default information
provided.
Returns None if it is not found (reports problems with file and puts
1 in retval), Some meaning otherwise
retval : Puts 1 here if an error ocurrs.
pos_file : Position of element to reference in case of error.
dname : Name of default definitions file.
defs : AST of default definitions (contents of dname).
fname : Name of file to use (or empty if the default must be used).
id : Identification of the meaning. Must have '.'
Reference to a word
val check_refmeaning : int Pervasives.ref ->
int Pervasives.ref ->
('a -> unit) ->
string ->
('b Markup_document.extension Markup_document.node as 'b) list ->
(string * string, string) Hashtbl.t ->
< attribute : string -> Markup_types.att_value; pos_file : string;
sub_nodes : 'a list; .. > ->
unit
check_refmeaning retval words check_son dname defs hw elem Checks the
node elem of a referenced word.
retval : Puts 1 here if an error ocurrs.
words : Reference to amount of words (it will increment it in 1)
check_son : Function to check the sons of the node.
dname : Name of default definitions file.
defs : AST of default definitions (contents of dname).
hw : Hashing table with ids of referenced words, if the current
word is there report problem otherwise adds it.
elem : Element
Classifications and sequences
val extract_subtree : string ->
string ->
string ->
((< attribute : string -> Markup_types.att_value;
node_type : Markup_document.node_type; sub_nodes : 'a; .. >
as 'b)
list as 'a) ->
'b option
extract_subtree nelem typc id l Extracts from l the subtree that begins
in an element nelem with the attributes tipo and id with
values typc and id
val next_id_sc : string * string -> string * string
next_id_sc (idp,idr) Returns next part of an identification of a
sequence or a classification (idp',idr') where idp' is next
part. Each part is separated with a dot.
The first invocation can be ("",idc)
val extract_subtree_file : int Pervasives.ref ->
string ->
string ->
('a Markup_document.extension Markup_document.node as 'a) list ->
string -> string -> string -> string -> 'a option
extract_subtree_file retval pos_file dname forest nroot name_elem
typc idm extracts a subtree name_elem with type typc and
identification id, if necessary opening the appropriate file or
using the default information provided dname, forest.
Returns None if it is not found (reports problems with file and puts 1
in retval), Some subtree otherwise.
retval : Puts 1 here if an error ocurrs.
pos_file : Position of element to reference in case of error.
dname : Name of default file.
forest : List of AST of default forest (contents of dname).
nroot : Name of root element in DTD.
name_elem : Name of element to look for.
typc : Type.
idm : Identification.
val extract_classif_file : int Pervasives.ref ->
string ->
string ->
('a Markup_document.extension Markup_document.node as 'a) list ->
string -> string -> 'a option
extract_classif_file retval pos_file dname dcla typc idc
Extracts a classification subtree with name typc, id idc
possibly opening the necessary file or using the default
information provided dname dcla.
Returns None if it is not found (reports problems with file and puts 1
in retval), Some subtree otherwise.
retval : Puts 1 here if an error ocurrs.
pos_file : Position of element to reference in case of error.
dname : Name of default file.
dcla : List of AST of default forest (contents of dname).
typc : Type to look for.
idc : Identification to look for.
val extract_seq_file : int Pervasives.ref ->
string ->
string ->
('a Markup_document.extension Markup_document.node as 'a) list ->
string -> string -> 'a option
extract_seq_file retval pos_file dname dseq typs ids Extracts
a sequence subtree with id ids, type typs, possibly opening
the necessary file or using the default information provided dname
dseq.
Returns None if it is not found (reports problems with file and puts 1
in retval), Some subtree otherwise.
retval : Puts 1 here if an error ocurrs.
pos_file : Position of element to reference in case of error.
dname : Name of default file.
dseq : List of AST of default forest (contents of dname).
typs : Type to look for.
ids : Identification to look for.
val check_refclassif : int Pervasives.ref ->
int Pervasives.ref ->
bool ->
(string ->
'a list ->
string -> (< node_type : Markup_document.node_type; .. > as 'b) -> 'a list) ->
string ->
('c Markup_document.extension Markup_document.node as 'c) list ->
(string * string, string) Hashtbl.t ->
'a list ->
< attribute : string -> Markup_types.att_value; pos_file : string;
sub_nodes : 'b list; .. > ->
'a list
check_refclassif retval classifs idwithfile check_elem dname dclassif
hclassif lres elem
Checks a reference to a classification elem. Reports problems in
attributes, indicates if the refered classification exists (by
opening the referring file using if apropriate default information
dname dclasif or if it is repeated and checks children.
Returns lres concatenated with the responses from childs.
classifs : Counter of classifications.
idwithfile : If true the identification is checked to ensure it has
a file (i.e of the form file:id)
check_elem : Function to check a child element, it must receive:
idc lres nelem elem. idc is id of referenced classification,
lres is a list that is constructed by this
function, nelem the name of the element and elem the element
to check. It must return a list of the same type of lres
---the returns list will be concatenated with lres in other
invocations and the final result of lres will be returned by this
function.
dname : Name of the default classifications file
dclassif : Defautl ast.
hclassif : Hash table with classifications (id) and their position,
to ensure that there are not repeated classifications.
lres : List where the answers of childs will be concatenated.
It will be returned at end of checking.
elem : Element clasif to check.
val ext_add_cs : string ->
string ->
string * string ->
string ->
Markup_dtd.dtd ->
(('a Markup_document.node as 'b) Markup_document.extension as 'a)
Markup_document.node ->
'b list -> bool * 'a Markup_document.node option * string
ext_add_cs name_elem typ (idp,idr) desc dtd parent l extracts or
adds to the forest l son of parent (sequence or
classification with dtd dtd), an element name_elem according to the
identification idp^"."^idr (see function next_id_sc) and type typ.
This function can add only up to one level more in types that the
existing in th file.
If it has to add a node, it will have description desc.
Returns (exists,node,msg) where exists indicates if the
node existed (false means that it would be added).
node is None if the node cannot be found neither added
or Some n with the node
msg is an error message when node is None.
val docbook2txt : string -> string
val parse_format : 'a -> string -> string -> string -> knownFormats * int option
parse_format retval pos_file f l Parses format name f.
Returns A pair with type of format (knownFormats) and optional length.
retval : Puts 1 here if an error ocurrs.
pos_file : In case of error position to report.
f : Format name.
val for2txt : string -> string -> string
for2txt f s translates the string s using the format f.
f : Name of format
s : String to translate.
val for2tex : string -> string -> string
for2tex f s translates the string s using the format f to TeX.
f : Pair with type for format (knownFormats) and optional length.
s : String to translate.
val for2for : knownFormats -> knownFormats -> string -> string
for2for fin fout s if possible, translates the string s from format
fin in format fout
val check_text_format : int Pervasives.ref ->
knownFormats * int option -> string -> string -> unit
check_text_format retval format pos_file d Checks the string d
with respect to format format.
retval : Puts 1 here if an error ocurrs.
format : Pair with type for format (knownFormats) and optional length.
pos_file : In case of error position to report.