1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| module type TextAnalysis_type = sig
type lemma
type word
type phrase
val make_word : int -> word
val distance_bw : word -> word -> int
val distance_bp : phrase -> phrase -> float
end
module TextAnalysis_firstAttempt : TextAnalysis_type = struct
type lemma = int
type word = Word of int
type phrase = word list
let make_word lemma = Word(lemma)
let distance_bw w1 w2 = (* distance between words *)
let Word i1, Word i2 = w1, w2 in (i1-i2)*(i1-i2)
let distance_bp p1 p2 = (* distance between phrases *)
failwith "Not implemented yet"
end
module MyFirstTextAnalysis : TextAnalysis_type = TextAnalysis_firstAttempt
module TextAnalysis_sndAttempt : TextAnalysis_type = struct
type lemma = int
type word = {lemma : lemma}
type phrase = word list
let make_word lemma = {lemma = lemma}
let distance_bw w1 w2 = (* distance between words *)
let i1, i2 = w1.lemma, w2.lemma in (i1-i2)*(i1-i2)
let distance_bp phr1 phr2 = (* distance between phrases *)
List.map2 distance_bw phr1 phr2
|> TextAnalysisUtils.int_median
end
module MySndTextAnalysis : TextAnalysis_type = TextAnalysis_firstAttempt |