FWIW, here's an only slightly unionized version that runs instantly:

PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rex:   <http://jug.basistech.com/2011/01/rex-entity#>
# prefixed used for injected predicate constraint, at least in a unit test.
prefix rules:  <http://www.basistech.com/ontologies/2010/12/rules#>

CONSTRUCT {
  ?root ?p ?o .
  ?root ?rp ?orel .
  ?orel ?p2 ?o2 .
  ?osub ?p3 ?osubobj .
  ?rei1 ?rei_p1 ?rei_o1 .
  ?rei2 ?rei_p2 ?rei_o2 .

}
WHERE
{
 GRAPH <urn:jug:global> {
  {
    # All the triples that have the desired text.
         ?root (rex:text|rex:alternativeText) "Bongani Khumalo" .
    # all the triples with that subject.
         ?root ?p ?o .
         FILTER (?p IN (rex:alternateText, rex:text,
rex:translatedText, rex:corefChainDisplayDescription,
                 rex:corefChainDisplayName, rex:documentId, rdf:type))
        {
         ?root ?rp ?orel .
         FILTER (?rp IN
(<http://jug.basistech.com/2011/01/rex-entity#hasEmail>,
<http://www.basistech.com/ontologies/2010/12/rules#hasPosition>,
<http://www.basistech.com/ontologies/2010/12/rules#supplierOf>,
<http://www.basistech.com/ontologies/2010/12/rules#hasParent>,
<http://www.basistech.com/ontologies/2010/12/rules#withinOrganization>,
<http://www.basistech.com/ontologies/2010/12/rules#hasEmail>,
<http://www.basistech.com/ontologies/2010/12/rules#hasChild>,
<http://jug.basistech.com/2011/01/rex-entity#communicatedWith>,
<http://jug.basistech.com/2011/01/rex-entity#traveledTo>,
<http://jug.basistech.com/2011/01/rex-entity#emailCcCoOccurence>,
<http://www.basistech.com/ontologies/2010/12/rules#locatedAt>,
<http://www.basistech.com/ontologies/2010/12/rules#traveledTo>,
<http://www.basistech.com/ontologies/2010/12/rules#releasedProduct>,
<http://jug.basistech.com/2011/01/rex-entity#withinOrganization>,
<http://www.basistech.com/ontologies/2010/12/rules#hasSpouse>,
<http://www.basistech.com/ontologies/2010/12/rules#acquired>,
<http://www.basistech.com/ontologies/2010/12/rules#hasSibling>,
<http://jug.basistech.com/2011/01/rex-entity#metadataRelationship>,
<http://jug.basistech.com/2011/01/rex-entity#hasSpouse>,
<http://jug.basistech.com/2011/01/rex-entity#ruleRelationship>,
<http://jug.basistech.com/2011/01/rex-entity#hasSibling>,
<http://jug.basistech.com/2011/01/rex-entity#hasPosition>,
<http://jug.basistech.com/2011/01/rex-entity#hasRelative>,
<http://jug.basistech.com/2011/01/rex-entity#emailFromTo>,
<http://jug.basistech.com/2011/01/rex-entity#hasParent>,
<http://www.basistech.com/ontologies/2010/12/rules#costOfObject>,
<http://www.basistech.com/ontologies/2010/12/rules#phoneNumber>,
<http://jug.basistech.com/2011/01/rex-entity#hasChild>,
<http://jug.basistech.com/2011/01/rex-entity#coOccurInSentence>,
<http://www.basistech.com/ontologies/2010/12/rules#hasRelative>,
<http://www.basistech.com/ontologies/2010/12/rules#communicatedWith>,
<http://www.basistech.com/ontologies/2010/12/rules#nameChangeTo>))
          # all our triples about s2.
          ?orel ?p2 ?o2 .
          FILTER (?p2 IN (rex:alternateText, rex:text,
rex:translatedText, rex:corefChainDisplayDescription,
                 rex:corefChainDisplayName, rex:documentId, rdf:type))
          # grab reifications of rels between root and s2.
          ?rei1 rdf:subject ?root .
          ?rei1 rdf:object ?orel .
          ?rei1 rdf:predicate ?rp .
          # and all the facts about the rel.
          ?rei1 ?rei_p1 ?rei_o1 .
        } UNION {
         ?osub ?rp2 ?root .
         FILTER (?rp2 IN
(<http://jug.basistech.com/2011/01/rex-entity#hasEmail>,
<http://www.basistech.com/ontologies/2010/12/rules#hasPosition>,
<http://www.basistech.com/ontologies/2010/12/rules#supplierOf>,
<http://www.basistech.com/ontologies/2010/12/rules#hasParent>,
<http://www.basistech.com/ontologies/2010/12/rules#withinOrganization>,
<http://www.basistech.com/ontologies/2010/12/rules#hasEmail>,
<http://www.basistech.com/ontologies/2010/12/rules#hasChild>,
<http://jug.basistech.com/2011/01/rex-entity#communicatedWith>,
<http://jug.basistech.com/2011/01/rex-entity#traveledTo>,
<http://jug.basistech.com/2011/01/rex-entity#emailCcCoOccurence>,
<http://www.basistech.com/ontologies/2010/12/rules#locatedAt>,
<http://www.basistech.com/ontologies/2010/12/rules#traveledTo>,
<http://www.basistech.com/ontologies/2010/12/rules#releasedProduct>,
<http://jug.basistech.com/2011/01/rex-entity#withinOrganization>,
<http://www.basistech.com/ontologies/2010/12/rules#hasSpouse>,
<http://www.basistech.com/ontologies/2010/12/rules#acquired>,
<http://www.basistech.com/ontologies/2010/12/rules#hasSibling>,
<http://jug.basistech.com/2011/01/rex-entity#metadataRelationship>,
<http://jug.basistech.com/2011/01/rex-entity#hasSpouse>,
<http://jug.basistech.com/2011/01/rex-entity#ruleRelationship>,
<http://jug.basistech.com/2011/01/rex-entity#hasSibling>,
<http://jug.basistech.com/2011/01/rex-entity#hasPosition>,
<http://jug.basistech.com/2011/01/rex-entity#hasRelative>,
<http://jug.basistech.com/2011/01/rex-entity#emailFromTo>,
<http://jug.basistech.com/2011/01/rex-entity#hasParent>,
<http://www.basistech.com/ontologies/2010/12/rules#costOfObject>,
<http://www.basistech.com/ontologies/2010/12/rules#phoneNumber>,
<http://jug.basistech.com/2011/01/rex-entity#hasChild>,
<http://jug.basistech.com/2011/01/rex-entity#coOccurInSentence>,
<http://www.basistech.com/ontologies/2010/12/rules#hasRelative>,
<http://www.basistech.com/ontologies/2010/12/rules#communicatedWith>,
<http://www.basistech.com/ontologies/2010/12/rules#nameChangeTo>))
          # all our triples about s2.
          ?osub ?p3 ?osubobj .
          FILTER (?p3 IN (rex:alternateText, rex:text,
rex:translatedText, rex:corefChainDisplayDescription,
                 rex:corefChainDisplayName, rex:documentId, rdf:type))
          # grab reifications of rels between root and s2.
          ?rei2 rdf:subject ?osub .
          ?rei2 rdf:object ?root .
          ?rei2 rdf:predicate ?rp2 .
          # and all the facts about the rel.
          ?rei2 ?rei_p2 ?rei_o2 .
        }
  }
 }
}

Reply via email to