[Fencommits] fenfire-hs: use graphURI in containsInfoTriples and findStartPath
Tuukka Hastrup
Tuukka.Hastrup at iki.fi
Sat Mar 17 10:35:08 EET 2007
Sat Mar 17 10:32:24 EET 2007 Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
* use graphURI in containsInfoTriples and findStartPath
diff -rN -u old-fenfire-hs-1/Fenfire/Main.hs new-fenfire-hs-1/Fenfire/Main.hs
--- old-fenfire-hs-1/Fenfire/Main.hs 2007-03-17 10:35:08.000000000 +0200
+++ new-fenfire-hs-1/Fenfire/Main.hs 2007-03-17 10:35:08.000000000 +0200
@@ -231,14 +231,13 @@
"open" -> confirmSave modified $ do
result <- liftIO $ openFile filepath
maybeDo result $ \(g',fp') -> do
- uri <- liftM IRI $ liftIO $ Raptor.filenameToURI fp'
- let ts = containsInfoTriples uri g'
+ let ts = containsInfoTriples g'
g'' = foldr insertVirtual g' ts
- put $ newState g'' (findStartPath uri g'') fp' focus
+ put $ newState g'' (findStartPath Nothing g'') fp' focus
"loadIRI" -> case node of
IRI uri -> do
g <- liftIO $ loadGraph uri
- let ts = containsInfoTriples (IRI uri) g
+ let ts = containsInfoTriples g
g' = foldr insertVirtual
(mergeGraphs graph g) ts
s' = state {fsGraph=g',
@@ -248,9 +247,8 @@
_ -> unhandledEvent
"revert" | filepath /= "" -> confirmRevert modified $ do
g' <- liftIO $ loadGraph filepath
- gNode <- liftM IRI $ liftIO $ Raptor.filenameToURI filepath
- let g'' = foldr insertVirtual g' $ containsInfoTriples gNode g'
- put $ newState g'' (findStartPath gNode g'') filepath focus
+ let g'' = foldr insertVirtual g' $ containsInfoTriples g'
+ put $ newState g'' (findStartPath Nothing g'') filepath focus
"save" | filepath /= "" -> do
liftIO $ saveGraph graph filepath
modify $ \s -> s { fsGraphModified = False }
@@ -482,12 +480,12 @@
fileName:fileNames <- mapM f xs
g' <- loadGraph fileName
gs <- mapM loadGraph fileNames
- uri <- Raptor.filenameToURI fileName
- uris <- mapM Raptor.filenameToURI fileNames
- let ts = concatMap (uncurry containsInfoTriples) $
- (IRI uri, g') : zip (map IRI uris) gs
+ let h x | List.isPrefixOf "http:" x = return x
+ | otherwise = Raptor.filenameToURI x
+ uri <- h fileName
+ let ts = concatMap containsInfoTriples (g':gs)
graph = foldr insertVirtual (foldl mergeGraphs g' gs) ts
- newIORef $ newState graph (findStartPath (IRI uri) graph) fileName False
+ newIORef $ newState graph (findStartPath (Just uri) graph) fileName False
-- start:
diff -rN -u old-fenfire-hs-1/Fenfire.fhs new-fenfire-hs-1/Fenfire.fhs
--- old-fenfire-hs-1/Fenfire.fhs 2007-03-17 10:35:08.000000000 +0200
+++ new-fenfire-hs-1/Fenfire.fhs 2007-03-17 10:35:08.000000000 +0200
@@ -208,13 +208,17 @@
let graph = listToGraph [(home, rdfs_label, Literal "" Plain)]
return (graph, Path home [])
-findStartPath :: (?vs :: ViewSettings) => Node -> Graph -> Path
-findStartPath self g = let ?graph = g in result where
+findStartPath :: (?vs :: ViewSettings) => Maybe String -> Graph -> Path
+findStartPath (Just uri) g = let ?graph = g in toPath' $ Rotation (IRI uri) 0
+findStartPath Nothing g = let ?graph = g in result where
result :: (?graph :: Graph) => Path
- result = head $ catMaybes $ startNode:topic:triples where
+ result = head $ catMaybes $ startNode:topic:document:triples where
+
+ self = IRI $ graphURI g
startNode = fmap getRot' $ getTriple self ffv_startNode
topic = fmap getRot' $ getTriple self foaf_primaryTopic
+ document = toPath (Rotation self 0) Pos
triples = map (Just . getRot) $ graphToList g
getTriple s p = fmap (\o -> (s,p,o)) $ getOne g s p Pos
@@ -224,22 +228,24 @@
ffv_startNode = IRI "http://fenfire.org/rdf-v/2003/05/ff#startNode"
foaf_primaryTopic = IRI "http://xmlns.com/foaf/0.1/primaryTopic"
-containsInfoTriples :: (?vs :: ViewSettings) => Node -> Graph -> [Triple]
-containsInfoTriples s g = [(s, p, o) | o <- os, o /= s] where
+containsInfoTriples :: (?vs :: ViewSettings) => Graph -> [Triple]
+containsInfoTriples g = [(s, p, o) | o <- os, o /= s] where
+ s = IRI $ graphURI g
p = IRI "ex:containsInformationAbout"
triples = graphToList g
[subjects, objects] = for [subject, object] $ \f -> map f triples
os = Set.toAscList $ foldr Set.delete (Set.fromList subjects) objects
loadGraph :: FilePath -> IO Graph
-loadGraph fileName = do
- --file <- readFile fileName
- --graph <- fromNTriples file >>= return . reverse-}
- uri <- Raptor.filenameToURI fileName
- (raptorTriples, namespaces) <- if List.isPrefixOf "http:" fileName
- then Raptor.uriToTriples fileName Nothing
- else Raptor.filenameToTriples fileName Nothing
- return $ raptorToGraph raptorTriples namespaces uri
+loadGraph fileName =
+ if List.isPrefixOf "http:" fileName
+ then loadGraph' Raptor.uriToTriples fileName
+ else do uri <- Raptor.filenameToURI fileName
+ loadGraph' Raptor.filenameToTriples uri
+
+loadGraph' load' uri = do
+ (raptorTriples, namespaces) <- load' uri Nothing
+ return $ raptorToGraph raptorTriples namespaces (takeWhile (/= '#') uri)
saveGraph :: Graph -> FilePath -> IO ()
saveGraph graph fileName = do
More information about the Fencommits
mailing list