Portability | FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances |
---|---|
Stability | experimental |
Maintainer | Douglas Burke |
This module defines a memory-based RDF graph instance.
- data RDFLabel
- isLiteral :: RDFLabel -> Bool
- isUntypedLiteral :: RDFLabel -> Bool
- isTypedLiteral :: RDFLabel -> Bool
- isXMLLiteral :: RDFLabel -> Bool
- isDatatyped :: ScopedName -> RDFLabel -> Bool
- isMemberProp :: RDFLabel -> Bool
- isUri :: RDFLabel -> Bool
- isBlank :: RDFLabel -> Bool
- isQueryVar :: RDFLabel -> Bool
- getLiteralText :: RDFLabel -> String
- getScopedName :: RDFLabel -> ScopedName
- makeBlank :: RDFLabel -> RDFLabel
- type RDFTriple = Arc RDFLabel
- data NSGraph lb = NSGraph {
- namespaces :: NamespaceMap
- formulae :: FormulaMap lb
- statements :: [Arc lb]
- type RDFGraph = NSGraph RDFLabel
- type NamespaceMap = LookupMap Namespace
- type RevNamespaceMap = LookupMap RevNamespace
- data RevNamespace
- emptyNamespaceMap :: NamespaceMap
- data LookupFormula lb gr = Formula {}
- type Formula lb = LookupFormula lb (NSGraph lb)
- type FormulaMap lb = LookupMap (LookupFormula lb (NSGraph lb))
- emptyFormulaMap :: FormulaMap RDFLabel
- addArc :: Label lb => Arc lb -> NSGraph lb -> NSGraph lb
- merge :: Label lb => NSGraph lb -> NSGraph lb -> NSGraph lb
- allLabels :: Label lb => (lb -> Bool) -> NSGraph lb -> [lb]
- allNodes :: Label lb => (lb -> Bool) -> NSGraph lb -> [lb]
- remapLabels :: Label lb => [lb] -> [lb] -> (lb -> lb) -> NSGraph lb -> NSGraph lb
- remapLabelList :: Label lb => [lb] -> [lb] -> [(lb, lb)]
- newNode :: Label lb => lb -> [lb] -> lb
- newNodes :: Label lb => lb -> [lb] -> [lb]
- setNamespaces :: NamespaceMap -> NSGraph lb -> NSGraph lb
- getNamespaces :: NSGraph lb -> NamespaceMap
- setFormulae :: FormulaMap lb -> NSGraph lb -> NSGraph lb
- getFormulae :: NSGraph lb -> FormulaMap lb
- setFormula :: Label lb => Formula lb -> NSGraph lb -> NSGraph lb
- getFormula :: Label lb => NSGraph lb -> lb -> Maybe (NSGraph lb)
- toRDFGraph :: [Arc RDFLabel] -> RDFGraph
- emptyRDFGraph :: RDFGraph
- class (Eq (lg lb), Eq lb) => LDGraph lg lb where
- setArcs :: [Arc lb] -> lg lb -> lg lb
- getArcs :: lg lb -> [Arc lb]
- extract :: Selector lb -> lg lb -> lg lb
- add :: lg lb -> lg lb -> lg lb
- delete :: lg lb -> lg lb -> lg lb
- labels :: lg lb -> [lb]
- nodes :: lg lb -> [lb]
- containedIn :: lg lb -> lg lb -> Bool
- update :: ([Arc lb] -> [Arc lb]) -> lg lb -> lg lb
- class (Eq lb, Show lb, Ord lb) => Label lb where
- data Arc lb = Arc {}
- arc :: lb -> lb -> lb -> Arc lb
- arcSubj :: Arc lb -> lb
- arcPred :: Arc lb -> lb
- arcObj :: Arc lb -> lb
- type Selector lb = Arc lb -> Bool
- res_rdf_type :: RDFLabel
- res_rdf_first :: RDFLabel
- res_rdf_rest :: RDFLabel
- res_rdf_nil :: RDFLabel
- res_rdfs_member :: RDFLabel
- res_rdfd_GeneralRestriction :: RDFLabel
- res_rdfd_onProperties :: RDFLabel
- res_rdfd_constraint :: RDFLabel
- res_rdfd_maxCardinality :: RDFLabel
- res_owl_sameAs :: RDFLabel
- res_log_implies :: RDFLabel
- grMatchMap :: Label lb => NSGraph lb -> NSGraph lb -> (Bool, LabelMap (ScopedLabel lb))
- grEq :: Label lb => NSGraph lb -> NSGraph lb -> Bool
- mapnode :: Label lb => [lb] -> [lb] -> (lb -> lb) -> lb -> lb
- maplist :: Label lb => [lb] -> [lb] -> (lb -> lb) -> [(lb, lb)] -> [(lb, lb)]
Documentation
RDF graph node values
cf. http://www.w3.org/TR/rdf-concepts/#section-Graph-syntax
This is extended from the RDF abstract graph syntax in the following ways:
(a) a graph can be part of a resource node or blank node (cf. Notation3 formulae)
(b) a "variable" node option is distinguished from a blank node. I have found this useful for encoding and handling queries, even though query variables can be expressed as blank nodes.
(c) a "NoNode" option is defined.
This might otherwise be handled by Maybe (RDFLabel g)
.
isUntypedLiteral :: RDFLabel -> BoolSource
Test if supplied labal is an untyped literal node
isTypedLiteral :: RDFLabel -> BoolSource
Test if supplied labal is an untyped literal node
isXMLLiteral :: RDFLabel -> BoolSource
Test if supplied labal is an XML literal node
isDatatyped :: ScopedName -> RDFLabel -> BoolSource
Test if supplied label is an typed literal node of a given datatype
isMemberProp :: RDFLabel -> BoolSource
Test if supplied label is a container membership property
Check for namespace is RDF namespace and first character of local name is '_' and remaining characters of local name are all digits
isQueryVar :: RDFLabel -> BoolSource
Test if supplied labal is a query variable
getLiteralText :: RDFLabel -> StringSource
Extract text value from a literal node
getScopedName :: RDFLabel -> ScopedNameSource
Extract ScopedName value from a resource node
makeBlank :: RDFLabel -> RDFLabelSource
Make a blank node from a supplied query variable, or return the supplied label unchanged. (Use this in when substituting an existential for an unsubstituted query variable.)
Memory-based graph with namespaces and subgraphs
NSGraph | |
|
Functor NSGraph | |
Foldable NSGraph | |
Traversable NSGraph | |
ShowM RDFGraph | |
Label lb => LDGraph NSGraph lb | |
LookupEntryClass NamedGraph ScopedName [RDFGraph] | |
Label lb => Eq (NSGraph lb) | |
Label lb => Show (NSGraph lb) | |
Label lb => Show (LookupFormula lb (NSGraph lb)) | |
Label lb => LookupEntryClass (LookupFormula lb (NSGraph lb)) lb (NSGraph lb) |
type NamespaceMap = LookupMap NamespaceSource
Namespace prefix list entry
data LookupFormula lb gr Source
Graph formula entry
(Eq lb, Eq gr) => Eq (LookupFormula lb gr) | |
Label lb => Show (LookupFormula lb (NSGraph lb)) | |
Label lb => LookupEntryClass (LookupFormula lb (NSGraph lb)) lb (NSGraph lb) |
type Formula lb = LookupFormula lb (NSGraph lb)Source
type FormulaMap lb = LookupMap (LookupFormula lb (NSGraph lb))Source
merge :: Label lb => NSGraph lb -> NSGraph lb -> NSGraph lbSource
Merge RDF graphs, renaming blank and query variable nodes as needed to neep variable nodes from the two graphs distinct in the resulting graph.
allLabels :: Label lb => (lb -> Bool) -> NSGraph lb -> [lb]Source
Return list of all labels (including properties) in the graph satisfying a supplied filter predicate.
allNodes :: Label lb => (lb -> Bool) -> NSGraph lb -> [lb]Source
Return list of all subjects and objects in the graph satisfying a supplied filter predicate.
:: Label lb | |
=> [lb] | variable nodes to be renamed ( |
-> [lb] | variable nodes used that must be avoided ( |
-> (lb -> lb) | node conversion function that is applied to nodes
from |
-> NSGraph lb | graph in which nodes are to be renamed |
-> NSGraph lb |
Remap selected nodes in graph:
This is the node renaming operation that prevents graph-scoped variable nodes from being merged when two graphs are merged.
:: Label lb | |
=> [lb] | labels to be remaped |
-> [lb] | labels to be avoided by the remapping |
-> [(lb, lb)] |
Externally callable function to construct a list of (old,new) values to be used for graph label remapping.
newNode :: Label lb => lb -> [lb] -> lbSource
Given a node and a list of existing nodes, find a new node for the supplied node that does not clash with any existing node. (Generates an non-terminating list of possible replacements, and picks the first one that isn't already in use.)
TODO: optimize this for common case nnn
and _nnn
:
always generate _nnn
and keep track of last allocated
newNodes :: Label lb => lb -> [lb] -> [lb]Source
Given a node and a list of existing nodes, generate a list of new nodes for the supplied node that do not clash with any existing node.
setNamespaces :: NamespaceMap -> NSGraph lb -> NSGraph lbSource
getNamespaces :: NSGraph lb -> NamespaceMapSource
setFormulae :: FormulaMap lb -> NSGraph lb -> NSGraph lbSource
getFormulae :: NSGraph lb -> FormulaMap lbSource
toRDFGraph :: [Arc RDFLabel] -> RDFGraphSource
Create a new RDF graph from a supplied list of arcs
emptyRDFGraph :: RDFGraphSource
Create a new, empty RDF graph.
class (Eq (lg lb), Eq lb) => LDGraph lg lb whereSource
Labelled Directed Graph class
Minimum required implementation: setArcs
, getArcs
and containedIn
.
NOTE: I wanted to declare this as a subclass of Functor, but the constraint on the label type seems to prevent that. So I've just declared specific instances to be Functors.
setArcs :: [Arc lb] -> lg lb -> lg lbSource
Replace the existing arcs in the graph.
getArcs :: lg lb -> [Arc lb]Source
Extract all the arcs from a graph
extract :: Selector lb -> lg lb -> lg lbSource
Extract those arcs that match the given Selector
.
add :: lg lb -> lg lb -> lg lbSource
Add the two graphs
:: lg lb | g1 |
-> lg lb | g2 |
-> lg lb | g2 - g1 -> g3 |
Remove those arcs in the first graph from the second graph
Enumerate the distinct labels contained in a graph;
that is, any label that appears in the subject,
predicate or object position of an Arc
.
Enumerate the distinct nodes contained in a graph;
that is, any label that appears in the subject
or object position of an Arc
.
containedIn :: lg lb -> lg lb -> BoolSource
Test for graph containment in another.
update :: ([Arc lb] -> [Arc lb]) -> lg lb -> lg lbSource
Update the arcs in a graph using a supplied function.
class (Eq lb, Show lb, Ord lb) => Label lb whereSource
Label class
A label may have a fixed binding, which means that the label identifies (is) a particular graph node, and different such labels are always distinct nodes. Alternatively, a label may be unbound (variable), which means that it is a placeholder for an unknown node label. Unbound node labels are used as graph-local identifiers for indicating when the same node appears in several arcs.
For the purposes of graph-isomorphism testing, fixed labels are matched when they are the same. Variable labels may be matched with any other variable label. Our definition of isomorphism (for RDF graphs) does not match variable labels with fixed labels.
labelIsVar :: lb -> BoolSource
Does this node have a variable binding?
labelHash :: Int -> lb -> IntSource
Calculate the hash of the label using the supplied seed.
getLocal :: lb -> StringSource
Extract the local id from a variable node.
makeLabel :: String -> lbSource
Make a label value from a local id.
Arc type
:: lb | The subject of the arc. |
-> lb | The predicate of the arc. |
-> lb | The object of the arc. |
-> Arc lb |
Create an arc.
grMatchMap :: Label lb => NSGraph lb -> NSGraph lb -> (Bool, LabelMap (ScopedLabel lb))Source
mapnode :: Label lb => [lb] -> [lb] -> (lb -> lb) -> lb -> lbSource
Remap a single graph node.
If the node is not one of those to be remapped, the supplied value is returned unchanged.
maplist :: Label lb => [lb] -> [lb] -> (lb -> lb) -> [(lb, lb)] -> [(lb, lb)]Source
Construct a list of (oldnode,newnode) values to be used for graph label remapping. The function operates recursiovely, adding new nodes generated to the mapping list (mapbn') and also to the list of nodes to be avoided (allbn').