4Suite™ API Documentation

# ► Module Ft.Rdf.Parsers.Versa.CoreFunctions

Core Versa functions
Copyright 2005 Fourthought, Inc. (USA).
Detailed license and copyright information: http://4suite.org/COPYRIGHT
Project home, documentation, distributions: http://4suite.org/

Classes:
curry

Functions:
All, And, Boolean, Concat, Contains, ContainsCi, Current, Difference, Distribute, Evaluate, Filter, Head, Intersection, IsLiteral, IsResource, IsType, Item, Join, Length, List, Map, Member, Not, Number, Or, Order, Properties, RelFunc, Resource, Rest, Scope, ScopedSubquery, Set, ShiftContext, Sort, SortQ, StartsWith, String, StringLength, SubstringAfter, SubstringBefore, Tail, Traverse, Triples, Type, Union

Fields:
Eq, FUNCTIONS, Gt, Gte, Lt, Lte, RDF_MS_BASE, RDF_SCHEMA_BASE, RDF_SUBCLASSOF_PROP, RDF_SUBPROPOF_PROP, RDF_TYPE_PROP

## Classes

class curry
# See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549 # This does slow down these functions, but to an extent that is drowned out by the general slowness of function dispatch in Versa

### Methods

__call__(self, *args, **kwargs)
__init__(self, fun, *args, **kwargs)

## Functions

All(con)
Get all resources in the system returns a list of strings (resources) Note, if this was all()[] Then a FilterFunction is created
And(con, *args)
Logical conjunction
Boolean(con, obj)
Concat(con, *args)
Concatenate a list of strings
Contains(con, arg1, arg2=None)
contains(outer, inner) Return true if inner is contained in outer.
ContainsCi(con, arg1, arg2=None)
contains(outer, inner) Return true if inner is contained in outer. Case insensitive variation
Current(con)
Return the current value, if there is one
Difference(con, arg1, arg2)
Set difference
Distribute(con, sourceList, *exprs)
Apply a list of expression to a list of values, returning a list of a list of the results. sourceList - a list of values exprs - the remaining arguments are all converted to strings and treated as Versa expressions which are applied to each item of sourceList
Evaluate(con, expr)
Dynamically evaluate the given string
Filter(con, sourceList, *filters)
Apply a boolean expression to each of the resources The first argument must return a list of resources The second is a list of boolean-expressions. the return value is the list of filtered resources
Head(con, l, num=1)
Converts the first argument to a list L, and the second to a number N. Returns a list consisting of the first N items in L. N defaults to 1. If N is negative, or exceeds the length of the list, the entire list is the result.
Intersection(con, *args)
Set intersection
IsLiteral(con, obj)
If computed argument is a list or set, convert to list and return true if the first member is a literal, otherwise return true if arg is a literal
IsResource(con, arg)
Return true if the item is of type resource, or can be successfully converted to resource
IsType(con, obj, type_)
If obj resolves to a list, return true if any member is of the types If obj is not a list, return true if the item is of one of the specifed types
Item(con, l, num=1)
Converts the first argument to a list L, and the second to a number N. Returns the Nth item in L. N defaults to 1.
Join(con, *args)
Create a new list
Length(con, obj)
Return the length of a list
List(con, *args)
Create a new list
Map(con, expr, *argLists)
Execute an expression using each item of a given list, in turn, as context expr - converted to strings and treated as Versa expressions argLists - remaining arguments are each iterated over in turn to form the argument Apply the query to each of the resources in the resource Expression. The first argument must be a list of resources The second is a list of queries. the results is a list of lists. The nested list will can the result of each of the queries.
Member(con, arg1, arg2=None)
member(outer, inner) Return true if inner is a member of outer.
Not(con, arg)
Logical negation
Number(con, obj)
Or(con, *args)
Logical disjunction
Order(con, subjs, pred, dirn=u'http://rdfinference.org/versa/0/2/traverse/forward')
Properties(con, res=None)
Note: This could take advantage of RDF/RDFS/OWL entailment rules to *bypass* doing a brute force search on the model or to augment the result with other properties infered via rdfs:subPropertyOf and rdfs7
http://www.w3.org/TR/rdf-mt/#RDFRules [7.3 RDFS Entailment Rules]
Transitivity of rdfs:subPropertyOf (rdfs5) could be used to return additional properties related to those returned
Assuming res has a defining OWL ontology, the rdfs:domain relationships stated in that ontology could be used
to deduce properties of res. So
scoped-subquery('res - rdfs:domain -> infered-property',<ontology>)
where <ontology> is a defining model for res and other related resources
In addition, under extensional semantic conditions (http://www.w3.org/TR/2004/REC-rdf-mt-20040210/#RDFSExtRules)
additional rdfs:domain relationships can be deduced from within this defining ontology:
ext1, ext3,
RelFunc(con, left, right=None, cmp_results=None)
Resource(con, obj)
Rest(con, l, num=1)
Converts the first argument to a list L, and the second to a number N. Returns a list consisting of all items in L after position N. N defaults to 1. If N is negative, or exceeds the length of the list, an empty list is the result. The following expression returns the same list as L, regardless of the value of N:
Scope(con, res)
Returns the scope(s) in which the given typed subject(s) is/are defined. i.e. the scope of it's rdf:type statement (if one exists)
ScopedSubquery(con, expr, scope)
Evaluate a subexpression within the limits of a given scope
Set(con, *args)
Create a new set. If the argument is a single list, it is converted to a similar set If the argument is one or more scalar value, it is converted to a set with those values Otherwise, it is an error, and you may have meant to use the flatten() function
ShiftContext(con, new)
Sort(con, sourceList=None, type_=u'http://rdfinference.org/versa/0/2/sort/string', order=u'http://rdfinference.org/versa/0/2/sort/ascending')
Sort the given set or list. If there are no arguments, the context is sorted using default params The first argument is converted to a list The second argument is the optional sort type The third argument is the optional sort order The results are the sorted list
SortQ(con, sourceList, expr, type_=u'http://rdfinference.org/versa/0/2/sort/string', order=u'http://rdfinference.org/versa/0/2/sort/ascending')
Dynamically sort using the given set or list. The first argument is converted to a list The second argument is the expression to be dynamically evaluated per list item The third argument is the optional sort type The fourth argument is the optional sort order The results are the sorted list
StartsWith(con, arg1, arg2=None)
starts-with(outer, inner) Return true if outer starts with inner.
String(con, obj)
StringLength(con, obj)
Return the length of a string
SubstringAfter(con, arg1, arg2=None)
SubstringBefore(con, arg1, arg2=None)
Tail(con, l, num=1)
Converts the first argument to a list L, and the second to a number N. Returns a list consisting of the last N items in L. N defaults to 1. If N is negative, or exceeds the length of the list, an empty list is the result.
Traverse(con, subjs, preds, dirn=u'http://rdfinference.org/versa/0/2/traverse/forward', trans=u'http://rdfinference.org/versa/0/2/traverse/simple')
Triples(con, matchSubj, matchPred, matchObj)
Return a list of triples matching the given criteria
Type(con, types)
Get all resources of a specific type. This takes into account rdfs:subClassOf ala RDFS Entailment rule rdfs9 (http://www.w3.org/TR/rdf-mt/#RDFRules) 7.3 RDFS Entailment Rules
uuu rdfs:subClassOf xxx .
vvv rdf:type xxx . --> vvv rdf:type uuu .
Other possible rdf:type entailments:
rdfs2
aaa rdfs:domain xxx .
uuu aaa yyy . ---> uuu rdf:type xxx .
Versa solution (? - skolem variable):
Infered-member |- (list(types) <- rdfs:domain - ?) -> ?
rdfs3
aaa rdfs:range xxx .
uuu aaa vvv . --> vvv rdf:type xxx .
Versa solution (? - skolem variable)
? - (list(types) <- rdfs:range - ?) -> Infered-member
Where infered-member is a resource returned amongst the list resulting from this evaluateion of type()
Union(con, *args)
Set union

## Fields

Eq = <Ft.Rdf.Parsers.Versa.CoreFunctions.curry instance>
FUNCTIONS = {(None, 'all'): <function All>, (None, 'and'): <function And>, (None, 'boolean'): <function Boolean>, (None, 'concat'): <function Concat>, (None, 'contains'): <function Contains>, (None, 'contains-ci'): <function ContainsCi>, (None, 'current'): <function Current>, (None, 'difference'): <function Difference>, (None, 'distribute'): <function Distribute>, (None, 'eq'): <Ft.Rdf.Parsers.Versa.CoreFunctions.curry instance>, ...}
Gt = <Ft.Rdf.Parsers.Versa.CoreFunctions.curry instance>
Gte = <Ft.Rdf.Parsers.Versa.CoreFunctions.curry instance>
Lt = <Ft.Rdf.Parsers.Versa.CoreFunctions.curry instance>
Lte = <Ft.Rdf.Parsers.Versa.CoreFunctions.curry instance>
RDF_MS_BASE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
RDF_SCHEMA_BASE = 'http://www.w3.org/2000/01/rdf-schema#'
RDF_SUBCLASSOF_PROP = u'http://www.w3.org/2000/01/rdf-schema#subClassOf'
RDF_SUBPROPOF_PROP = u'http://www.w3.org/2000/01/rdf-schema#subPropertyOf'
RDF_TYPE_PROP = u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'