Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added proper handling for "Collection" parseType (example 19 working)

Ignore-this: 13880ef1dc34c11c5bc79000c3c931a

darcs-hash:20110201000904-1786f-96c38c1f1f373fd0080d6d6417bcf56381463122.gz
  • Loading branch information...
commit 4abaa1b2dce93ae79a7f24e1e9ebceaca6f9765a 1 parent 7df8031
@amccausl authored
Showing with 15 additions and 8 deletions.
  1. +15 −8 src/Text/RDF/RDF4H/XmlParser.hs
View
23 src/Text/RDF/RDF4H/XmlParser.hs
@@ -92,16 +92,17 @@ parsePredicatesFromAttr s = getAttrl >>> ((getName
parsePredicatesFromChildren :: forall a. (ArrowXml a, ArrowState GParseState a) => a (LParseState, XmlTree) Triple
parsePredicatesFromChildren = updateState
>>> choiceA [ second (hasAttrValue "rdf:parseType" (== "Literal")) :-> arr2A parseAsLiteralTriple
- , second (hasAttrValue "rdf:parseType" (== "Collection")) :-> arr2A parseAsCollectionTriples
, second (hasAttrValue "rdf:parseType" (== "Resource")) :-> arr2A parseAsResourceTriples
+ , second (hasAttrValue "rdf:parseType" (== "Collection")) :-> (listA (defaultA >>> arr id &&& mkBlankNode) >>> mkCollectionTriples >>> unlistA)
, second (hasAttr "rdf:datatype") :-> arr2A getTypedTriple
, second (hasAttr "rdf:resource") :-> arr2A getResourceTriple
, second (hasAttr "rdf:nodeID") :-> arr2A getNodeIdTriple
- , this :-> proc (state, predXml) -> do
- p <- arr(unode . s2b) <<< getName -< predXml
- t <- arr2A (\s -> arr2A (parseObjectsFromChildren s)) <<< second (second getChildren) -< (state, (p, predXml))
- returnA -< t
+ , this :-> defaultA
]
+ where defaultA = proc (state, predXml) -> do
+ p <- arr(unode . s2b) <<< getName -< predXml
+ t <- arr2A (\s -> arr2A (parseObjectsFromChildren s)) <<< second (second getChildren) -< (state, (p, predXml))
+ returnA -< t
parseObjectsFromChildren :: forall a. (ArrowXml a, ArrowState GParseState a)
=> LParseState -> Predicate -> a XmlTree Triple
@@ -129,9 +130,15 @@ parseAsLiteralTriple :: forall a. (ArrowXml a, ArrowState GParseState a) => LPar
parseAsLiteralTriple state = ((getName >>> arr (unode . s2b)) &&& (xshow ( getChildren ) >>> arr (mkTypedLiteralNode state nodeType))) >>> arr (attachSubject (stateSubject state))
where nodeType = mkFastString (s2b "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral")
--- TODO
-parseAsCollectionTriples :: forall a. (ArrowXml a, ArrowState GParseState a) => LParseState -> a XmlTree Triple
-parseAsCollectionTriples state = none
+mkCollectionTriples :: forall a. (ArrowXml a, ArrowState GParseState a) => a [(Triple, Node)] Triples
+mkCollectionTriples = arr (mkCollectionTriples' [])
+ where mkCollectionTriples' [] ((Triple s1 p1 o1, n1):rest) = mkCollectionTriples' [Triple s1 p1 n1] ((Triple s1 p1 o1, n1):rest)
+ mkCollectionTriples' acc ((Triple s1 p1 o1, n1):(t2, n2):rest) = mkCollectionTriples' (Triple n1 headNode o1 : Triple n1 tailNode n2 : acc) ((t2, n2):rest)
+ mkCollectionTriples' acc ((Triple s1 p1 o1, n1):[]) = Triple n1 headNode o1 : Triple n1 tailNode nilNode : acc
+ mkCollectionTriples' acc [] = []
+ headNode = (unode . s2b) "rdf:first"
+ tailNode = (unode . s2b) "rdf:rest"
+ nilNode = (unode . s2b) "rdf:nil"
parseAsResourceTriples :: forall a. (ArrowXml a, ArrowState GParseState a) => LParseState -> a XmlTree Triple
parseAsResourceTriples state = ((getName >>> arr (unode . s2b)) &&& (getAttrValue "rdf:resource" >>> arr (unode . s2b))) >>> arr (attachSubject (stateSubject state))
Please sign in to comment.
Something went wrong with that request. Please try again.