Softwaredesign: Suchen im Zitatenschatz |
|
1module IndexExample
2where
3
4import Data.Char
5import Data.List
6
7import qualified Data.Set as S
8
9import Index
10
11import Zitate
12
13-- ------------------------------------------------------------
14--
15-- der Index-Aufbau
16
17zitateIx :: Index
18zitateIx = foldr (indexDocument' istVonInteresse) emptyIndex
19 .
20 map (\ (n, z) -> (show n, scanText z) )
21 $
22 zitate
23
24-- ------------------------------------------------------------
25--
26-- der Filter fuer die unwichtigen Woerter
27
28istVonInteresse :: String -> Bool
29istVonInteresse w
30 = length w > 1
31 &&
32 w `notElem` [ "und", "oder", "nicht",
33 "ich", "du", "er", "sie", "es", "wir", "ihr",
34 "bin", "bist", "ist", "sind", "seid",
35 "der", "die", "das", "dem", "den", "des",
36 "ein", "eine", "einer",
37 "nur",
38 "mein", "meine", "meiner", "dein", "sein",
39 "ihn", "ihr", "uns",
40 "von", "vom",
41 "wer", "wie", "was",
42 "wieso", "weshalb", "warum",
43 "wenn", "werde", "werden",
44 "wurde", "wurden", "will",
45 "zum", "zur"
46 ]
47 &&
48 not (all isDigit w)
49
50-- ------------------------------------------------------------
51--
52-- die Anfragen
53
54wortSuche :: String -> IO ()
55wortSuche w
56 = gefundeneZitate (`S.member` res)
57 where
58 res = documentNames . searchIndex w $ zitateIx
59
60praefixSuche :: String -> IO ()
61praefixSuche p
62 = gefundeneZitate (`S.member` res)
63 where
64 res = documentNames . prefixSearchIndex p $ zitateIx
65
66-- ------------------------------------------------------------
67
68gefundeneZitate :: (DocumentName -> Bool) -> IO()
69gefundeneZitate isRes
70 = putStrLn
71 $
72 concatMap (\ (_wer, was) -> breakLines was ++ "\n")
73 .
74 sort
75 .
76 filter (\ (wer, _was) -> isRes (show wer))
77 $
78 zitate
79
80alleZitate :: IO()
81alleZitate = gefundeneZitate (const True)
82
83-- ------------------------------------------------------------
84--
85-- wichtige einfache Anfragen
86
87bayern = wortSuche "Bayern"
88merkel = wortSuche "Merkel"
89willi = wortSuche "Willi"
90loddar = praefixSuche "Matt"
91trainer = praefixSuche "Train"
92
93-- ------------------------------------------------------------
94--
95--
96
97breakLines :: String -> String
98breakLines s
99 = line ++ word ++ "\n"
100 ++
101 ( if null rest2
102 then ""
103 else "\t" ++ breakLines (dropWhile isSpace rest2)
104 )
105 where
106 (line, rest) = splitAt 50 s
107 (word, rest2) = span (not . isSpace) rest
108
109-- ------------------------------------------------------------
|
Letzte Änderung: 10.07.2012 | © Prof. Dr. Uwe Schmidt |