[Fencommits] fenfire-hs: initial Irc2RDF
Tuukka Hastrup
Tuukka.Hastrup at iki.fi
Thu Mar 1 02:37:08 EET 2007
Thu Mar 1 02:37:06 EET 2007 Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
* initial Irc2RDF
diff -rN -u old-fenfire-hs/fenfire.cabal new-fenfire-hs/fenfire.cabal
--- old-fenfire-hs/fenfire.cabal 2007-03-01 02:37:07.000000000 +0200
+++ new-fenfire-hs/fenfire.cabal 2007-03-01 02:37:07.000000000 +0200
@@ -53,3 +53,11 @@
-fno-warn-unused-imports -fno-warn-missing-signatures
-fno-warn-orphans -fno-warn-deprecations
-main-is Darcs2RDF.main
+
+Executable: irc2rdf
+Main-Is: Irc2RDF.hs
+Other-Modules: Irc2RDF
+GHC-Options: -fglasgow-exts -hide-package haskell98 -Wall
+ -fno-warn-unused-imports -fno-warn-missing-signatures
+ -fno-warn-orphans -fno-warn-deprecations
+ -main-is Irc2RDF.main
diff -rN -u old-fenfire-hs/Irc2RDF.hs new-fenfire-hs/Irc2RDF.hs
--- old-fenfire-hs/Irc2RDF.hs 1970-01-01 02:00:00.000000000 +0200
+++ new-fenfire-hs/Irc2RDF.hs 2007-03-01 02:37:07.000000000 +0200
@@ -0,0 +1,49 @@
+
+module Irc2RDF where
+
+import System.Time (getClockTime, toUTCTime, CalendarTime(..))
+import System.Environment (getArgs)
+import System.IO (hFlush, stdout)
+
+main = do [root] <- getArgs
+ irc <- getContents
+ mapM_ (handle root)$ lines irc
+
+handle root line = do clockTime <- getClockTime
+ putStr $ irc2rdf root clockTime line
+ hFlush stdout
+
+irc2rdf root time = uncurry (triples root time) . parse
+
+parse (':':rest) = (Just $ takeWhile (/=' ') rest,
+ parse' "" (tail $ dropWhile (/=' ') rest))
+parse rest = (Nothing, parse' "" rest)
+
+parse' acc [] = [reverse acc]
+parse' acc ['\r'] = [reverse acc]
+parse' "" (':':xs) = [reverse . dropWhile (=='\r') $ reverse xs]
+parse' acc (' ':xs) = reverse acc : parse' "" xs
+parse' acc (x:xs) = parse' (x:acc) xs
+
+triples root time (Just prefix) ["PRIVMSG","#fenfire",msg] =
+ "<irc://freenode/%23fenfire> <"++isContainerOf++"> <"++uri++">.\n"++
+ "<"++uri++"> <"++created++"> "++show (day++"T"++second++"Z")++".\n"++
+ "<"++uri++"> <"++hasCreator++"> <"++creator++">.\n"++
+ "<"++uri++"> <"++hasContent++"> "++show msg++".\n"++
+ "<"++uri++"> <"++label++"> "++show ("<"++nick++"> "++msg)++".\n"++
+ "<"++creator++"> <"++label++"> "++show nick++".\n"
+ where label = "http://www.w3.org/2000/01/rdf-schema#label"
+ created = "http://purl.org/dc/terms/created"
+ isContainerOf = "http://rdfs.org/sioc/ns#is_container_of"
+ hasCreator = "http://rdfs.org/sioc/ns#has_creator"
+ hasContent = "http://rdfs.org/sioc/ns#has_content"
+ uri = root ++ day ++ "#" ++ second
+ nick = takeWhile (/='!') prefix
+ creator = "irc://freenode/"++nick++",isuser"
+ (CalendarTime y moe d h m s _ps _wd _yd _tzn _tz _isDST)
+ = toUTCTime time
+ mo = (fromEnum moe+1)
+ p n i = take (n-length (show i)) (repeat '0') ++ show i
+ day = p 4 y ++ '-':p 2 mo ++ '-':p 2 d
+ second = p 2 h ++ ':':p 2 m ++ ':':p 2 s
+triples _ _ _ _ = ""
diff -rN -u old-fenfire-hs/Makefile new-fenfire-hs/Makefile
--- old-fenfire-hs/Makefile 2007-03-01 02:37:07.000000000 +0200
+++ new-fenfire-hs/Makefile 2007-03-01 02:37:07.000000000 +0200
@@ -13,7 +13,7 @@
PREPROCESSED=$(patsubst %.fhs,%.hs,$(wildcard *.fhs)) \
$(patsubst %.chs,%.hs,$(wildcard *.chs))
SOURCES=*.hs *.chs *.fhs $(PREPROCESSED)
-TARGETS=functortest vobtest fenfire darcs2rdf
+TARGETS=functortest vobtest fenfire darcs2rdf irc2rdf
all: build
@@ -29,13 +29,14 @@
rm -f $(TARGETS)
$(MAKE) all
-functortest vobtest fenfire darcs2rdf: build
+functortest vobtest fenfire darcs2rdf irc2rdf: build
run-functortest: functortest
run-vobtest: vobtest
run-fenfire: ARGS=test.nt
run-fenfire: fenfire
run-darcs2rdf: darcs2rdf
+run-irc2rdf: irc2rdf
run-%: %
./dist/build/$</$< $(ARGS)
More information about the Fencommits
mailing list