[Fencommits] fenfire-hs: offsets for irc lines with the same timestamp

Tuukka Hastrup Tuukka.Hastrup at iki.fi
Thu Mar 1 12:39:38 EET 2007


Thu Mar  1 12:18:07 EET 2007  Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
  * offsets for irc lines with the same timestamp
diff -rN -u old-fenfire-hs/Irc2RDF.hs new-fenfire-hs/Irc2RDF.hs
--- old-fenfire-hs/Irc2RDF.hs	2007-03-01 12:39:37.000000000 +0200
+++ new-fenfire-hs/Irc2RDF.hs	2007-03-01 12:39:37.000000000 +0200
@@ -1,17 +1,32 @@
 
 module Irc2RDF where
 
-import System.Time (getClockTime, toUTCTime, CalendarTime(..))
+import System.Time (getClockTime, toUTCTime, CalendarTime(..), ClockTime(..))
 import System.Environment (getArgs)
 import System.IO (hFlush, stdout)
+import System.IO.Unsafe (unsafeInterleaveIO)
 
 main = do [root] <- getArgs
           irc <- getContents
-          mapM_ (handle root)$ lines irc
+          timestamps <- getTimeStamps
+          mapM_ (uncurry $ handle root) $ zip (lines irc) (uniquify timestamps)
 
-handle root line = do clockTime <- getClockTime
-                      putStr $ irc2rdf root clockTime line
-                      hFlush stdout
+getTimeStamps = do ~(TOD secs _picos) <- unsafeInterleaveIO getClockTime
+                   xs <- unsafeInterleaveIO getTimeStamps
+                   return (TOD secs 0:xs)
+
+uniquify     [] = []
+uniquify (x:xs) = (x,Nothing):uniquify' (x,Nothing) xs
+
+uniquify'    _     [] = []
+uniquify' prev (x:xs) | fst prev == x = next prev:uniquify' (next prev) xs
+                      | otherwise     =   first x:uniquify' (first x) xs
+    where next (i,offset) = (i, Just $ maybe (2::Integer) (+1) offset)
+          first i         = (i, Nothing)
+
+handle root line (clockTime,offset) = do 
+                                putStr $ irc2rdf root (clockTime,offset) line
+                                hFlush stdout
 
 irc2rdf root time = uncurry (triples root time) . parse
 
@@ -25,7 +40,7 @@
 parse' acc (' ':xs) = reverse acc : parse' "" xs
 parse' acc   (x:xs) = parse' (x:acc) xs
 
-triples root time (Just prefix) ["PRIVMSG","#fenfire",msg] =
+triples root (time,offset) (Just prefix) ["PRIVMSG","#fenfire",msg] =
     "<irc://freenode/%23fenfire> <"++isContainerOf++"> <"++uri++">.\n"++
     "<"++uri++"> <"++created++"> "++show (day++"T"++second++"Z")++".\n"++
     "<"++uri++"> <"++hasCreator++"> <"++creator++">.\n"++
@@ -37,7 +52,7 @@
           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
+          uri = root ++ day ++ "#" ++ second ++ maybe "" (('.':) . show) offset
           nick = takeWhile (/='!') prefix
           creator = "irc://freenode/"++nick++",isuser"
           (CalendarTime y moe d h m s _ps _wd _yd _tzn _tz _isDST) 




More information about the Fencommits mailing list