FuXi’s Documentation

FuXi is a Python-based, bi-directional logical reasoning system for the semantic web. FuXi aims to be the engine for contemporary expert systems based on the Semantic Web technologies. It is named after the first of the Three Sovereigns of ancient China. It originally formed from an idea to express the underlying symbols (and their relationships) in the Yi Jing or Zhou Yi (“The Book of Changes”) in OWL and RDF in order to reason over their structural relationships.

For an overview of the architecture, please read FuXi Overview and FuXi User Manual for more information.

Documentation of key classes and methods (referenced in above Wikis)

FuXi.Rete

An implementation of most of the RETE-UL algorithms outlined in the PhD thesis (1995) of Robert Doorenbos: Production Matching for Large Learning Systems. See FuXi.Rete in manual for how to use SetupRuleStore to create an ReteNetwork.

FuXi.Rete.RuleStore.SetupRuleStore(n3Stream=None, additionalBuiltins=None, makeNetwork=False)

Sets up a N3RuleStore, a Graph (that uses it as a store, and )

class FuXi.Rete.Network.ReteNetwork(ruleStore, name=None, initialWorkingMemory=None, inferredTarget=None, nsMap={}, graphVizOutFile=None, dontFinalize=False, goal=None)

The Rete network. The constructor takes an N3 rule graph, an identifier (a BNode by default), an initial Set of Rete tokens that serve as the ‘working memory’, and an rdflib Graph to add inferred triples to - by forward-chaining via Rete evaluation algorithm),

addWME(wme)
procedure add-wme (w: WME) exhaustive hash table versiong
let v1, v2, and v3 be the symbols in the three fields of w alpha-mem = lookup-in-hash-table (v1,v2,v3) if alpha-mem then alpha-memory-activation (alpha-mem, w) alpha-mem = lookup-in-hash-table (v1,v2,*) if alpha-mem then alpha-memory-activation (alpha-mem, w) alpha-mem = lookup-in-hash-table (v1,*,v3) if alpha-mem then alpha-memory-activation (alpha-mem, w) ... alpha-mem = lookup-in-hash-table (,,*) if alpha-mem then alpha-memory-activation (alpha-mem, w)

end

attachBetaNodes(patternIterator, lastBetaNodePattern=None)

The second ‘pass’ in the Rete network compilation algorithm: Attaches Beta nodes to the alpha nodes associated with all the patterns in a rule’s LHS recursively towards a ‘root’ Beta node - the terminal node for the rule. This root / terminal node is returned

buildFilterNetworkFromClause(rule)
buildNetwork(lhsIterator, rhsIterator, rule, aFilter=False)

Takes an iterator of triples in the LHS of an N3 rule and an iterator of the RHS and extends the Rete network, building / reusing Alpha and Beta nodes along the way (via a dictionary mapping of patterns to the built nodes)

buildNetworkFromClause(rule)
calculateStratifiedModel(database)

Stratified Negation Semantics for DLP using SPARQL to handle the negation

checkDuplicateRules()
clear()
closureGraph(sourceGraph, readOnly=True, store=None)
createAlphaNode(currentPattern)
feedFactsToAdd(tokenIterator)

Feeds the network an iterator of facts / tokens which are fed to the alpha nodes which propagate the matching process through the network

fireConsequent(tokens, termNode, debug=False)

“In general, a p-node also contains a specifcation of what production it corresponds to | the name of the production, its right-hand-side actions, etc. A p-node may also contain information about the names of the variables that occur in the production. Note that variable names are not mentioned in any of the Rete node data structures we describe in this chapter. This is intentional |it enables nodes to be shared when two productions have conditions with the same basic form, but with different variable names.”

Takes a set of tokens and the terminal Beta node they came from and fires the inferred statements using the patterns associated with the terminal node. Statements that have been previously inferred or already exist in the working memory are not asserted

getNsBindings(nsMgr)
parseN3Logic(src)
registerReteAction(headTriple, override, executeFn)

Register the given execute function for any rule with the given head using the override argument to determine whether or not the action completely handles the firing of the rule.

The signature of the execute action is as follows:

def someExecuteAction(tNode, inferredTriple, token, binding):
reportConflictSet(closureSummary=False, stream=<open file '<stdout>', mode 'w' at 0x1004160b8>)
reportSize(tokenSizeThreshold=1200, stream=<open file '<stdout>', mode 'w' at 0x1004160b8>)
reset(newinferredFacts=None)

Reset the network by emptying the memory associated with all Beta Nodes nodes

setupDescriptionLogicProgramming(owlN3Graph, expanded=[], addPDSemantics=True, classifyTBox=False, constructNetwork=True, derivedPreds=[], ignoreNegativeStratus=False, safety=0)

FuXi.Horn

FuXi includes an API that was originally implemented as a reference implementation of the W3C’s Rule Interchange Format Basic Logic Dialect but eventually evolved into a Pythonic API for managing an abstract Logic Programming syntax. It includes functions used for creating rulesets converted from OWL RDF expressions and creating a Horn ruleset from a parsed Notation 3 graph:

FuXi.Horn.HornRules.HornFromN3(n3Source, additionalBuiltins=None)

Takes the path or URL of a N3 document, and a mapping from predicates to functions that implement any builtins found in the N3 document

FuXi.Horn.HornRules.HornFromDL(owlGraph, safety=0, derivedPreds=[], complSkip=[])

Takes an OWL RDF graph, an indication of what level of ruleset safety (see: http://code.google.com/p/fuxi/wiki/FuXiUserManual#Rule_Safety) to apply, and a list of derived predicates and returns a Ruleset instance comprised of the rules extracted from the OWL RDF graph (using a variation of the OWL 2 RL transformation)

FuXi.Horn.HornRules.NetworkFromN3(n3Source, additionalBuiltins=None)

Takes an N3 / RDF conjunctive graph and returns a ReteNetwork built from the rules in the N3 graph

Below are the various classes and functions that comprise this API

The language of positive RIF conditions determines what can appear as a body (the

if-part) of a rule supported by the basic RIF logic. As explained in Section Overview, RIF’s Basic Logic Dialect corresponds to definite Horn rules, and the

bodies of such rules are conjunctions of atomic formulas without negation.
class FuXi.Horn.PositiveConditions.And(formulae=None, naf=False)

CONJUNCTION ::= ‘And’ ‘(‘ CONDITION* ‘)’

>>> And([Uniterm(RDF.type,[RDFS.comment,RDF.Property]),
...      Uniterm(RDF.type,[OWL.Class,RDFS.Class])])
And( rdf:Property(rdfs:comment) rdfs:Class(owl:Class) )
binds(var)

A variable, v, is bound in a conjunction formula, f = And(c1...cn), n ≥ 1, if and only if, either

  • v is bound in at least one of the conjuncts;

For now we don’t support equality predicates, so we only check the first condition

>>> x=Variable('X')
>>> y=Variable('Y')
>>> lit1 = Uniterm(RDF.type,[x,RDFS.Class])
>>> lit2 = Uniterm(RDF.Property,[y,RDFS.Class])
>>> conj = And([lit1,lit2])
>>> conj.binds(Variable('Y'))
True
>>> conj.binds(Variable('Z'))
False
isSafeForVariable(var)

A variable, v is safe in a condition formula if and only if ..

f is a conjunction, f = And(c1...cn), n ≥ 1, and v is safe in at least one conjunct in f

Since we currently don’t support equality predicates, we only check the first condition

>>> x=Variable('X')
>>> y=Variable('Y')
>>> lit1 = Uniterm(RDF.type,[x,RDFS.Class])
>>> lit2 = Uniterm(RDF.Property,[y,RDFS.Class])
>>> conj = And([lit1,lit2])
>>> conj.isSafeForVariable(y)
True
n3()
>>> And([Uniterm(RDF.type,[RDFS.comment,RDF.Property]),
...      Uniterm(RDF.type,[OWL.Class,RDFS.Class])]).n3()
u'rdfs:comment a rdf:Property .\n owl:Class a rdfs:Class'
class FuXi.Horn.PositiveConditions.Atomic

ATOMIC ::= Uniterm | Equal | Member | Subclass (| Frame)

binds(var)

A variable, v, is bound in an atomic formula, a, if and only if

  • a is neither an equality nor an external predicate, and v occurs as an argument in a;
  • or v is bound in the conjunction formula f = And(a).

Default is False

FuXi.Horn.PositiveConditions.BuildUnitermFromTuple((s, p, o), newNss=None)
class FuXi.Horn.PositiveConditions.Condition

CONDITION ::= CONJUNCTION | DISJUNCTION | EXISTENTIAL | ATOMIC

isSafeForVariable(var)

A variable, v is safe in a condition formula if and only if ..

class FuXi.Horn.PositiveConditions.Equal(lhs=None, rhs=None)

Equal ::= TERM ‘=’ TERM TERM ::= Const | Var | Uniterm | ‘External’ ‘(‘ Expr ‘)’

>>> Equal(RDFS.Resource,OWL.Thing)
rdfs:Resource =  owl:Thing
class FuXi.Horn.PositiveConditions.Exists(formula=None, declare=None)

EXISTENTIAL ::= ‘Exists’ Var+ ‘(‘ CONDITION ‘)’ >>> Exists(formula=Or([Uniterm(RDF.type,[RDFS.comment,RDF.Property]), ... Uniterm(RDF.type,[OWL.Class,RDFS.Class])]), ... declare=[Variable(‘X’),Variable(‘Y’)]) Exists ?X ?Y ( Or( rdf:Property(rdfs:comment) rdfs:Class(owl:Class) ) )

binds(var)

A variable, v, is bound in an existential formula, Exists v1,...,vn (f’), n ≥ 1, if and only if v is bound in f’

>>> ex=Exists(formula=And([Uniterm(RDF.type,[RDFS.comment,RDF.Property]),
...                    Uniterm(RDF.type,[Variable('X'),RDFS.Class])]),
...        declare=[Variable('X')])
>>> ex.binds(Variable('X'))
True
isSafeForVariable(var)

A variable, v is safe in a condition formula if and only if ..

f is an existential formula, f = Exists v1,...,vn (f’), n ≥ 1, and v is safe in f’ .

n3()
class FuXi.Horn.PositiveConditions.ExternalFunction(builtin, newNss=None)

An External(ATOMIC) is a call to an externally defined predicate, equality, membership, subclassing, or frame. Likewise, External(Expr) is a call to an externally defined function. >>> ExternalFunction(Uniterm(URIRef(‘http://www.w3.org/2000/10/swap/math#greaterThan’),[Variable(‘VAL’),Literal(2)])) math:greaterThan(?VAL “2”^^<http://www.w3.org/2001/XMLSchema#integer>)

class FuXi.Horn.PositiveConditions.Or(formulae=None, naf=False)

DISJUNCTION ::= ‘Or’ ‘(‘ CONDITION* ‘)’

>>> Or([Uniterm(RDF.type,[RDFS.comment,RDF.Property]),
...      Uniterm(RDF.type,[OWL.Class,RDFS.Class])])
Or( rdf:Property(rdfs:comment) rdfs:Class(owl:Class) )
binds(var)

A variable, v, is bound in a disjunction formula, if and only if v is bound in every disjunct where it occurs

>>> x=Variable('X')
>>> y=Variable('Y')
>>> lit1 = Uniterm(RDF.type,[x,RDFS.Class])
>>> lit2 = Uniterm(RDF.Property,[y,RDFS.Class])
>>> conj = And([lit1,lit2])
>>> disj = Or([conj,lit2])
>>> disj.binds(y)
True
>>> disj.binds(Variable('Z'))
False
>>> lit = Uniterm(RDF.type,[OWL.Class,RDFS.Class])
>>> disj= Or([lit,lit])
>>> disj.binds(x)
False
isSafeForVariable(var)

A variable, v is safe in a condition formula if and only if ..

f is a disjunction, and v is safe in every disjunct;

class FuXi.Horn.PositiveConditions.PredicateExtentFactory(predicateSymbol, binary=True, newNss=None)

Creates an object which when indexed returns a Uniterm with the ‘registered’ symbol and two-tuple argument

>>> from rdflib import Namespace, URIRef
>>> EX_NS = Namespace('http://example.com/')
>>> ns = {'ex':EX_NS}
>>> somePredFactory = PredicateExtentFactory(EX_NS.somePredicate,newNss=ns)
>>> somePredFactory[(EX_NS.individual1,EX_NS.individual2)]
ex:somePredicate(ex:individual1 ex:individual2)
>>> somePred2Factory = PredicateExtentFactory(EX_NS.somePredicate,binary=False,newNss=ns)
>>> somePred2Factory[EX_NS.individual1]
ex:somePredicate(ex:individual1)
term(name)
class FuXi.Horn.PositiveConditions.QNameManager(nsDict=None)
bind(prefix, namespace)
class FuXi.Horn.PositiveConditions.SetOperator
remove(item)
repr(operator)
class FuXi.Horn.PositiveConditions.Uniterm(op, arg=None, newNss=None, naf=False)

Uniterm ::= Const ‘(‘ TERM* ‘)’ TERM ::= Const | Var | Uniterm

We restrict to binary predicates (RDF triples)

>>> Uniterm(RDF.type,[RDFS.comment,RDF.Property])
rdf:Property(rdfs:comment)
applicableMapping(mapping)

Can the given mapping (presumably from variables to terms) be applied?

arity
binds(var)

A variable, v, is bound in an atomic formula, a, if and only if

  • a is neither an equality nor an external predicate, and v occurs as an argument in a;
  • or v is bound in the conjunction formula f = And(a).

Default is False

>>> x = Variable('X')
>>> lit = Uniterm(RDF.type,[RDFS.comment,x])
>>> lit.binds(Variable('Z'))
False
>>> lit.binds(x)
False
>>> Uniterm(RDF.type,[x,RDFS.Class]).binds(x)
True
collapseName(val)
getArity()
getVarMapping(otherLit, reverse=False)

Takes another Uniterm and in every case where the corresponding term for both literals are different variables, we map from the variable for this uniterm to the corresponding variable of the other. The mapping will go in the other direction if the reverse keyword is True

>>> x = Variable('X')
>>> y = Variable('Y')
>>> lit1 = Uniterm(RDF.type,[RDFS.comment,x])
>>> lit2 = Uniterm(RDF.type,[RDFS.comment,y])
>>> lit1.getVarMapping(lit2)[x] == y
True
>>> lit1.getVarMapping(lit2,True)[y] == x
True
ground(varMapping)
isGround()
isSafeForVariable(var)

A variable, v is safe in a condition formula if and only if ..

f is an atomic formula and f is not an equality formula in which both terms are variables, and v occurs in f;

isSecondOrder()
n3()

Serialize as N3 (using available namespace managers)

>>> Uniterm(RDF.type,[RDFS.comment,RDF.Property]).n3()
u'rdfs:comment a rdf:Property'
normalizeTerm(term)
renameVariables(varMapping)
renderTermAsN3(term)
setOperator(newOp)
terms

Class attribute that returns all the terms of the literal as a lists >>> x = Variable(‘X’) >>> lit = Uniterm(RDF.type,[RDFS.comment,x]) >>> lit.terms [rdflib.URIRef(‘http://www.w3.org/1999/02/22-rdf-syntax-ns#type‘), rdflib.URIRef(‘http://www.w3.org/2000/01/rdf-schema#comment‘), ?X]

toRDFTuple()
FuXi.Horn.PositiveConditions.buildUniTerm((s, p, o), newNss=None)
FuXi.Horn.PositiveConditions.test()

FuXi.Rete.Magic

This module is where the Sideways Information Passing reasoning capabilities are implemented.

FuXi.Rete.Magic.MagicSetTransformation(factGraph, rules, GOALS, derivedPreds=None, strictCheck=2, noMagic=None, defaultPredicates=None)

Takes a goal and a ruleset and returns an iterator over the rulest that corresponds to the magic set transformation:

FuXi.SPARQL

Backward chaining algorithms for SPARQL RIF-Core and OWL 2 RL entailment. The Backwards Fixpoint Procedure (BFP) implementation uses RETE-UL as the RIF PRD implementation of a meta-interpreter of a ruleset that evaluates conjunctive (BGPs) SPARQL queries using a SPARQL 1.1 RIF Entailment Regime.

See: Overview and User Manual

class FuXi.SPARQL.BackwardChainingStore.TopDownSPARQLEntailingStore(store, edb, derivedPredicates=None, idb=None, DEBUG=False, nsBindings={}, decisionProcedure=0, templateMap=None, identifyHybridPredicates=False)

A Store which uses FuXi’s magic set “sip strategies” and the in-memory SPARQL Algebra implementation as a store-agnostic, top-down decision procedure for semanic web SPARQL (OWL2-RL/RIF/N3) entailment regimes. Exposed as a rdflib / layercake-python API for SPARQL datasets with entailment regimes Queries are mediated over the SPARQL protocol using global schemas captured as SW theories which describe and distinguish their predicate symbols

batch_unify(patterns)

Perform RDF triple store-level unification of a list of triple patterns (4-item tuples which correspond to a SPARQL triple pattern with an additional constraint for the graph name).

Uses a SW sip-strategy implementation to solve the conjunctive goal and yield unified bindings

Parameters :
  • patterns: a list of 4-item tuples where any of the items can be

    one of: Variable, URIRef, BNode, or Literal.

Returns a generator over dictionaries of solutions to the list of triple patterns that are entailed by the regime.

bind(prefix, namespace)
close(commit_pending_transaction=False)

This closes the database connection. The commit_pending_transaction parameter specifies whether to commit all pending transactions before closing (if the store is transactional).

commit()
conjunctiveSipStrategy(goalsRemaining, sipCollection, factGraph, bindings={})

Given a conjunctive set of triples, invoke sip-strategy passing on intermediate solutions to facilitate ‘join’ behavior

contexts(triple=None)

Generator over all contexts in the graph. If triple is specified, a generator over all contexts the triple is in.

derivedPredicateFromTriple((s, p, o))

Given a triple, return its predicate (if derived) or None otherwise

destroy(configuration)

This destroys the instance of the store identified by the configuration string.

getDerivedPredicates(expr, prolog)
invokeDecisionProcedure(tp, factGraph, bindings, debug, sipCollection)
isaBaseQuery(queryString, queryObj=None)

If the given SPARQL query involves purely base predicates it returns it (as a parsed string), otherwise it returns a SPARQL algebra instance for top-down evaluation using this store

>>> graph=Graph()
>>> topDownStore = TopDownSPARQLEntailingStore(graph.store,[RDFS.seeAlso],nsBindings={u'rdfs':RDFS.RDFSNS})
>>> rt=topDownStore.isaBaseQuery("SELECT * { [] rdfs:seeAlso [] }")
>>> isinstance(rt,(BasicGraphPattern,AlgebraExpression))
True
>>> rt=topDownStore.isaBaseQuery("SELECT * { [] a [] }")
>>> isinstance(rt,(Query,basestring))
True
>>> rt=topDownStore.isaBaseQuery("SELECT * { [] a [] OPTIONAL { [] rdfs:seeAlso [] } }")
>>> isinstance(rt,(BasicGraphPattern,AlgebraExpression))
True
namespace(prefix)
namespaces()
prefix(namespace)
rollback()
sparql_query(queryString, queryObj, graph, dataSetBase, extensionFunctions, initBindings={}, initNs={}, DEBUG=False)

The default ‘native’ SPARQL implementation is based on sparql-p’s expansion trees layered on top of the read-only RDF APIs of the underlying store

triples((subject, predicate, object), context=None)

A generator over all the triples matching the pattern. Pattern can include any objects for used for comparing against nodes in the store, for example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph, QuotedGraph, Date? DateRange?

A conjunctive query can be indicated by either providing a value of None for the context or the identifier associated with the Conjunctive Graph (if it’s context aware).

triples_choices((subject, predicate, object_), context=None)

A variant of triples that can take a list of terms instead of a single term in any slot. Stores can implement this to optimize the response time from the default ‘fallback’ implementation, which will iterate over each term in the list and dispatch to tripless

FuXi.Syntax

Includes the InfixOwl library (see the linked Wiki for more information). A Python binding for OWL Abstract Syntax that incorporates the Manchester OWL Syntax. See the Wiki and OWLED paper

RDFLib Python binding for OWL Abstract Syntax

see: http://www.w3.org/TR/owl-semantics/syntax.html
http://owl-workshop.man.ac.uk/acceptedLong/submission_9.pdf

3.2.3 Axioms for complete classes without using owl:equivalentClass

Named class description of type 2 (with owl:oneOf) or type 4-6 (with owl:intersectionOf, owl:unionOf or owl:complementOf

Uses Manchester Syntax for __repr__

>>> exNs = Namespace('http://example.com/')        
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', exNs, override=False)
>>> namespace_manager.bind('owl', OWL_NS, override=False)
>>> g = Graph()    
>>> g.namespace_manager = namespace_manager

Now we have an empty graph, we can construct OWL classes in it using the Python classes defined in this module

>>> a = Class(exNs.Opera,graph=g)

Now we can assert rdfs:subClassOf and owl:equivalentClass relationships (in the underlying graph) with other classes using the ‘subClassOf’ and ‘equivalentClass’ descriptors which can be set to a list of objects for the corresponding predicates.

>>> a.subClassOf = [exNs.MusicalWork]

We can then access the rdfs:subClassOf relationships

>>> print list(a.subClassOf)
[Class: ex:MusicalWork ]

This can also be used against already populated graphs:

#>>> owlGraph = Graph().parse(OWL_NS) #>>> namespace_manager.bind(‘owl’, OWL_NS, override=False) #>>> owlGraph.namespace_manager = namespace_manager #>>> list(Class(OWL_NS.Class,graph=owlGraph).subClassOf) #[Class: rdfs:Class ]

Operators are also available. For instance we can add ex:Opera to the extension of the ex:CreativeWork class via the ‘+=’ operator

>>> a
Class: ex:Opera SubClassOf: ex:MusicalWork
>>> b = Class(exNs.CreativeWork,graph=g)
>>> b += a
>>> print sorted(a.subClassOf,key=lambda c:c.identifier)
[Class: ex:CreativeWork , Class: ex:MusicalWork ]

And we can then remove it from the extension as well

>>> b -= a
>>> a
Class: ex:Opera SubClassOf: ex:MusicalWork

Boolean class constructions can also be created with Python operators For example, The | operator can be used to construct a class consisting of a owl:unionOf the operands:

>>> c =  a | b | Class(exNs.Work,graph=g)
>>> c
( ex:Opera or ex:CreativeWork or ex:Work )

Boolean class expressions can also be operated as lists (using python list operators)

>>> del c[c.index(Class(exNs.Work,graph=g))]
>>> c
( ex:Opera or ex:CreativeWork )

The ‘&’ operator can be used to construct class intersection:

>>> woman = Class(exNs.Female,graph=g) & Class(exNs.Human,graph=g)
>>> woman.identifier = exNs.Woman
>>> woman
( ex:Female and ex:Human )
>>> len(woman)
2

Enumerated classes can also be manipulated

>>> contList = [Class(exNs.Africa,graph=g),Class(exNs.NorthAmerica,graph=g)]
>>> EnumeratedClass(members=contList,graph=g)
{ ex:Africa ex:NorthAmerica }

owl:Restrictions can also be instanciated:

>>> Restriction(exNs.hasParent,graph=g,allValuesFrom=exNs.Human)
( ex:hasParent only ex:Human )

Restrictions can also be created using Manchester OWL syntax in ‘colloquial’ Python >>> exNs.hasParent |some| Class(exNs.Physician,graph=g) ( ex:hasParent some ex:Physician )

>>> Property(exNs.hasParent,graph=g) |max| Literal(1)
( ex:hasParent max 1 )

#>>> print g.serialize(format=’pretty-xml’)

FuXi.Syntax.InfixOWL.AllClasses(graph)
FuXi.Syntax.InfixOWL.AllDifferent(members)

DisjointClasses(‘ description description { description } ‘)’

FuXi.Syntax.InfixOWL.AllProperties(graph)
class FuXi.Syntax.InfixOWL.AnnotatibleTerms(identifier, graph=None)

Terms in an OWL ontology with rdfs:label and rdfs:comment

comment
label
seeAlso
class FuXi.Syntax.InfixOWL.BooleanClass(identifier=None, operator=rdflib.URIRef('http://www.w3.org/2002/07/owl#intersectionOf'), members=None, graph=None)

See: http://www.w3.org/TR/owl-ref/#Boolean

owl:complementOf is an attribute of Class, however

changeOperator(newOperator)

Converts a unionOf / intersectionOf class expression into one that instead uses the given operator

>>> testGraph = Graph()
>>> Individual.factoryGraph = testGraph
>>> EX = Namespace("http://example.com/")
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', EX, override=False)
>>> testGraph.namespace_manager = namespace_manager
>>> fire  = Class(EX.Fire)
>>> water = Class(EX.Water) 
>>> testClass = BooleanClass(members=[fire,water])
>>> testClass
( ex:Fire and ex:Water )
>>> testClass.changeOperator(OWL_NS.unionOf)
>>> testClass
( ex:Fire or ex:Water )
>>> try: testClass.changeOperator(OWL_NS.unionOf)
... except Exception, e: print e
The new operator is already being used!
copy()

Create a copy of this class

isPrimitive()
serialize(graph)
class FuXi.Syntax.InfixOWL.BooleanClassExtentHelper(operator)
>>> testGraph = Graph()
>>> Individual.factoryGraph = testGraph
>>> EX = Namespace("http://example.com/")
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', EX, override=False)
>>> testGraph.namespace_manager = namespace_manager
>>> fire  = Class(EX.Fire)
>>> water = Class(EX.Water) 
>>> testClass = BooleanClass(members=[fire,water])
>>> testClass2 = BooleanClass(operator=OWL_NS.unionOf,members=[fire,water])
>>> for c in BooleanClass.getIntersections():
...     print c
( ex:Fire and ex:Water )
>>> for c in BooleanClass.getUnions():
...     print c
( ex:Fire or ex:Water )
class FuXi.Syntax.InfixOWL.Callable(anycallable)
FuXi.Syntax.InfixOWL.CastClass(c, graph=None)
class FuXi.Syntax.InfixOWL.Class(identifier=None, subClassOf=None, equivalentClass=None, disjointWith=None, complementOf=None, graph=None, skipOWLClassMembership=False, comment=None)

‘General form’ for classes:

The Manchester Syntax (supported in Protege) is used as the basis for the form of this class

See: http://owl-workshop.man.ac.uk/acceptedLong/submission_9.pdf:

‘Class:’ classID {Annotation
( (‘SubClassOf:’ ClassExpression) | (‘EquivalentTo’ ClassExpression) | (’DisjointWith’ ClassExpression)) }

Appropriate excerpts from OWL Reference:

”.. Subclass axioms provide us with partial definitions: they represent
necessary but not sufficient conditions for establishing class membership of an individual.”

”.. A class axiom may contain (multiple) owl:equivalentClass statements”

”..A class axiom may also contain (multiple) owl:disjointWith statements..”

”..An owl:complementOf property links a class to precisely one class
description.”
annotation
complementOf
disjointWith
equivalentClass
extent
extentQuery
isPrimitive()
parents

computed attributes that returns a generator over taxonomic ‘parents’ by disjunction, conjunction, and subsumption

>>> exNs = Namespace('http://example.com/')
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', exNs, override=False)
>>> namespace_manager.bind('owl', OWL_NS, override=False)
>>> g = Graph()
>>> g.namespace_manager = namespace_manager
>>> Individual.factoryGraph = g
>>> brother = Class(exNs.Brother)
>>> sister  = Class(exNs.Sister)
>>> sibling = brother | sister
>>> sibling.identifier = exNs.Sibling
>>> sibling
( ex:Brother or ex:Sister )
>>> first(brother.parents)
Class: ex:Sibling EquivalentTo: ( ex:Brother or ex:Sister )
>>> parent = Class(exNs.Parent)
>>> male   = Class(exNs.Male)
>>> father = parent & male
>>> father.identifier = exNs.Father
>>> list(father.parents)
[Class: ex:Parent , Class: ex:Male ]
serialize(graph)
subClassOf
subSumpteeIds()
class FuXi.Syntax.InfixOWL.ClassNamespaceFactory
term(name)
FuXi.Syntax.InfixOWL.CommonNSBindings(graph, additionalNS={})

Takes a graph and binds the common namespaces (rdf,rdfs, & owl)

FuXi.Syntax.InfixOWL.ComponentTerms(cls)

Takes a Class instance and returns a generator over the classes that are involved in its definition, ignoring unamed classes

FuXi.Syntax.InfixOWL.DeepClassClear(classToPrune)

Recursively clear the given class, continuing where any related class is an anonymous class

>>> EX = Namespace('http://example.com/')
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', EX, override=False)
>>> namespace_manager.bind('owl', OWL_NS, override=False)
>>> g = Graph()    
>>> g.namespace_manager = namespace_manager    
>>> Individual.factoryGraph = g
>>> classB = Class(EX.B)
>>> classC = Class(EX.C)
>>> classD = Class(EX.D)
>>> classE = Class(EX.E)
>>> classF = Class(EX.F)
>>> anonClass = EX.someProp|some|classD
>>> classF += anonClass
>>> list(anonClass.subClassOf)
[Class: ex:F ]
>>> classA = classE | classF | anonClass    
>>> classB += classA
>>> classA.equivalentClass = [Class()]
>>> classB.subClassOf = [EX.someProp|some|classC]
>>> classA
( ex:E or ex:F or ( ex:someProp some ex:D ) )
>>> DeepClassClear(classA)
>>> classA
(  )
>>> list(anonClass.subClassOf)
[]
>>> classB
Class: ex:B SubClassOf: ( ex:someProp some ex:C )
>>> otherClass = classD | anonClass
>>> otherClass
( ex:D or ( ex:someProp some ex:D ) )
>>> DeepClassClear(otherClass)
>>> otherClass
(  )
>>> otherClass.delete()
>>> list(g.triples((otherClass.identifier,None,None)))
[]
class FuXi.Syntax.InfixOWL.EnumeratedClass(identifier=None, members=None, graph=None)

Class for owl:oneOf forms:

OWL Abstract Syntax is used

axiom ::= ‘EnumeratedClass(‘ classID [‘Deprecated’] { annotation } { individualID } ‘)’

>>> exNs = Namespace('http://example.com/')        
>>> namespace_manager = NamespaceManager(Graph())
>>> namespace_manager.bind('ex', exNs, override=False)
>>> namespace_manager.bind('owl', OWL_NS, override=False)
>>> g = Graph()    
>>> g.namespace_manager = namespace_manager
>>> Individual.factoryGraph = g
>>> ogbujiBros = EnumeratedClass(exNs.ogbujicBros,
...                              members=[exNs.chime,
...                                       exNs.uche,
...                                       exNs.ejike])
>>> ogbujiBros
{ ex:chime ex:uche ex:ejike }
>>> col = Collection(g,first(g.objects(predicate=OWL_NS.oneOf,subject=ogbujiBros.identifier)))
>>> [g.qname(item) for item in col]
[u'ex:chime', u'ex:uche', u'ex:ejike']
isPrimitive()
serialize(graph)
FuXi.Syntax.InfixOWL.GetIdentifiedClasses(graph)
class FuXi.Syntax.InfixOWL.Individual(identifier=None, graph=None)

A typed individual

clearInDegree()
clearOutDegree()
delete()
identifier
replace(other)
sameAs
serialize(graph)
type
class FuXi.Syntax.InfixOWL.Infix(function)
exception FuXi.Syntax.InfixOWL.MalformedClass(msg)
class FuXi.Syntax.InfixOWL.OWLRDFListProxy(rdfList, members=None, graph=None)
append(item)
clear()
index(item)
class FuXi.Syntax.InfixOWL.Ontology(identifier=None, imports=None, comment=None, graph=None)

The owl ontology metadata

imports
setVersion(version)
class FuXi.Syntax.InfixOWL.Property(identifier=None, graph=None, baseType=rdflib.URIRef('http://www.w3.org/2002/07/owl#ObjectProperty'), subPropertyOf=None, domain=None, range=None, inverseOf=None, otherType=None, equivalentProperty=None, comment=None)
axiom ::= ‘DatatypeProperty(‘ datavaluedPropertyID [‘Deprecated’] { annotation }
{ ‘super(‘ datavaluedPropertyID ‘)’} [‘Functional’] { ‘domain(‘ description ‘)’ } { ‘range(‘ dataRange ‘)’ } ‘)’
‘ObjectProperty(‘ individualvaluedPropertyID [‘Deprecated’] { annotation } { ‘super(‘ individualvaluedPropertyID ‘)’ } [ ‘inverseOf(‘ individualvaluedPropertyID ‘)’ ] [ ‘Symmetric’ ] [ ‘Functional’ | ‘InverseFunctional’ | ‘Functional’ ‘InverseFunctional’ | ‘Transitive’ ] { ‘domain(‘ description ‘)’ } { ‘range(‘ description ‘)’ } ‘)
domain
extent
inverseOf
range
serialize(graph)
subPropertyOf
class FuXi.Syntax.InfixOWL.Restriction(onProperty, graph=<Graph identifier=uSmOTjeK2 (<class 'rdflib.Graph.Graph'>)>, allValuesFrom=None, someValuesFrom=None, value=None, cardinality=None, maxCardinality=None, minCardinality=None, identifier=None)
restriction ::= ‘restriction(‘ datavaluedPropertyID dataRestrictionComponent
{ dataRestrictionComponent } ‘)’
‘restriction(‘ individualvaluedPropertyID individualRestrictionComponent { individualRestrictionComponent } ‘)’
allValuesFrom
cardinality
hasValue
isPrimitive()
maxCardinality
minCardinality
onProperty
restrictionKind()
serialize(graph)
>>> g1 = Graph()
>>> g2 = Graph()
>>> EX = Namespace("http://example.com/")
>>> namespace_manager = NamespaceManager(g1)
>>> namespace_manager.bind('ex', EX, override=False)
>>> namespace_manager = NamespaceManager(g2)
>>> namespace_manager.bind('ex', EX, override=False)
>>> Individual.factoryGraph = g1
>>> prop = Property(EX.someProp,baseType=OWL_NS.DatatypeProperty)
>>> restr1 = (Property(EX.someProp,baseType=OWL_NS.DatatypeProperty))|some|(Class(EX.Foo))
>>> restr1
( ex:someProp some ex:Foo )
>>> restr1.serialize(g2)
>>> Individual.factoryGraph = g2
>>> list(Property(EX.someProp,baseType=None).type)
[rdflib.URIRef('http://www.w3.org/2002/07/owl#DatatypeProperty')]
someValuesFrom
class FuXi.Syntax.InfixOWL.TermDeletionHelper(prop)
FuXi.Syntax.InfixOWL.classOrIdentifier(thing)
FuXi.Syntax.InfixOWL.classOrTerm(thing)
FuXi.Syntax.InfixOWL.generateQName(graph, uri)
FuXi.Syntax.InfixOWL.manchesterSyntax(thing, store, boolean=None, transientList=False)

Core serialization

FuXi.Syntax.InfixOWL.propertyOrIdentifier(thing)
FuXi.Syntax.InfixOWL.termDeletionDecorator(prop)
FuXi.Syntax.InfixOWL.test()

Indices and tables

Table Of Contents

This Page