问题
Introduction
I am programming a semantic web application in haskell.
With hsparql http://hackage.haskell.org/package/hsparql I can access my Tripple Store. Currently I use http://4store.org/ (mainly because it was easy to install). I use snap http://snapframework.com/ to do the servlet programming (Yesod is very cool too!!).
Currently I use SKOS to represent bookmarks categories in RDF.
Links on SKOS:
- http://www.w3.org/TR/skos-reference/
- http://www.athenaeurope.org/athenawiki/index.php/SKOS
Basically, a Skos Concept is a category. It has a URL (as kind of ID) and a Label. Further Skos Concepts can have sub concepts, defined with "broader" and "narrower".
For example in my bookmarks there is the SKOS concept "all bookmarks", with a sub concept "haskell bookmarks". And both concepts have a URL (e.g. as ID) and a Label. Also "haskell bookmarks" has a relation that the broader concept is "all bookmarks".
My Problem
I need a data structure in haskell for SKOS.
My current one is:
-- Type Aliases.
type Url = String
type Label = String
-- Date Structure.
data SkosConcept = SkosConcept {
url :: Url
, label :: Label
, subConcepts :: [SkosConcept]
} deriving (Show)
I think it's not a good way, but I don't know a better one.
Further, in the future the data structure needs to be extended to multiple labels, and means to store related concepts, ...
Also some concepts may not have any sub concepts.
Any pointers on how to improve the data structure or 'do it right'?
===== EDIT: ======
The problem is that a skos concept may have multiple broader skos concepts. So my "haskell bookmarks" can have two broader skos concepts (e.g. categories) named "programming bookmarks" and "my important bookmarks".
The only solutions I can think of at the moment is using:
- a directed graph for the "broader" relation of skos concepts
- a binary relation "broader" (but I don't know if there is good haskell support)
- no intermediate data structures and all my functions query the RDF Tripple Store
回答1:
Rather than trying to store a bidirectional structure directly, why not use the standard Graph approach, and store a tuple containing both the set of concepts, and containing the set of relations between concepts?
cf: http://hackage.haskell.org/package/fgl
来源:https://stackoverflow.com/questions/8032731/haskell-data-structure-for-skos-semantic-web