Phil; There are a couple of things preventing you from creating the union of all domains.  First, your ApplyConstruct is getting all domain matches, which explains the duplicate results.  Second, the Union syntax is a bit more complex, in that an rdf:list is needed to represent the union.

So attached is a solution that will do what you want.  Dean and worked on this a bit this afternoon and agree that some parts are not as pretty as we'd like, but it does the job.

It works by constructing a text list using ConcatenateText that is then converted to an rdf:list.  This will make sure that the union is created for all domains defined for a property.

I put some properties, testDomain1, testDomain2, testDomain3 in the file, so you can test the script.  Of course, you'll need to run a FilterByConstruct, or manipulate however you plan to create triples, to remove the existing domain definitions.

-- Scott

On 5/14/10 8:45 AM, [email protected] wrote:
I thought I should explain what I am trying

I have a script which ImportsRDFFromWorkspace then has an
iterateOverSelect with the sparql 
SELECT ?prop
WHERE {
	 ?prop a owl:DatatypeProperty .
    LET (?count := smf:countResults("SELECT ?domain WHERE { ?prop
rdfs:domain ?domain.}")) .
    FILTER (?count > 1) .
}

Then I have an ApplyConstruct linked to the body 
With the following as sparql
CONSTRUCT {
    _:b0 a owl:Class .
    _:b0 owl:unionOf ?domain .
    ?prop rdfs:domain _:b0 .
}
WHERE {
    ?prop rdfs:domain ?domain .
}

This gets me somewhere near where I want to be.
But I now have multiple union domains each with a single domain in it.

So I'm a biscuit short of packet and I can't seem to find that magic
statement that puts all the domains for a property in one unionOf
statement.

Cheers

Phil



  
-----Original Message-----
From: [email protected] [mailto:topbraid-
[email protected]] On Behalf Of [email protected]
Sent: 14 May 2010 14:04
To: [email protected]
Subject: [topbraid-users] SPARQL Construct to create union domains

Hi Guys.

I have a large ontology in which multiple domains of both object and
datatype properties have been defined individually. e.g.

vocabProperty:hasChain
      rdf:type owl:ObjectProperty ;
      rdfs:domain vocabClass:Antibody, vocabClass:Structure;
      rdfs:range vocabClass:Chain .

These should be union domains for it to work properly
e.g.

vocabProperty:hasChain
      rdf:type owl:ObjectProperty ;
      rdfs:domain
              [ rdf:type owl:Class ;
                owl:unionOf (vocabClass:Antibody vocabClass:Structure)
              ] ;
      rdfs:range vocabClass:Chain .

I could go through and edit the file by hand, but that's going to take
some time.
I'd prefer to use a sparql construct in a sparql motion script to do
    
it,
  
but I can't quite get it right.

Could anyone help me define the SM script to
1. find any property (object or datatype) with multiple domains
2. add the domains to create the unionOf statement.

Thanks in advance

Cheers

Phil

--------------------------------------------------------

UCB Celltech is the UK branch of UCB Pharma S.A., a company registered
    
in
  
Belgium with registered offices at Allee de la Recherche 60, 1070
Brussels, Belgium, KBO/BCE nr. 0403.096.168, RPR/RPM Brussels.
UCB Celltech's UK branch registration number is BR009137 and its UK
representative office is at 208 Bath Road, Slough, Berkshire SL1 3WE.
--------------------------------------------------------

Legal Notice: This electronic mail and its attachments are intended
    
solely
  
for the person(s) to whom they are addressed and contain information
    
which
  
is confidential or otherwise protected from disclosure, except for the
purpose for which they are intended. Dissemination, distribution, or
reproduction by anyone other than the intended recipients is
    
prohibited
  
and may be illegal. If you are not an intended recipient, please
immediately inform the sender and return the electronic mail and its
attachments and destroy any copies which may be in your possession.
    
UCB
  
screens electronic mails for viruses but does not warrant that this
electronic mail is free of any viruses. UCB accepts no liability for
    
any
  
damage caused by any virus transmitted by this electronic mail. (Ref:
#*CUK0308)
--------------------------------------------------------

--
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include TopBraid
Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en 
    
 
--------------------------------------------------------

UCB Celltech is the UK branch of UCB Pharma S.A., a company registered in Belgium with registered offices at Allee de la Recherche 60, 1070 Brussels, Belgium, KBO/BCE nr. 0403.096.168, RPR/RPM Brussels. 
UCB Celltech's UK branch registration number is BR009137 and its UK representative office is at 208 Bath Road, Slough, Berkshire SL1 3WE.
--------------------------------------------------------

Legal Notice: This electronic mail and its attachments are intended solely for the person(s) to whom they are addressed and contain information which is confidential or otherwise protected from disclosure, except for the purpose for which they are intended. Dissemination, distribution, or reproduction by anyone other than the intended recipients is prohibited and may be illegal. If you are not an intended recipient, please immediately inform the sender and return the electronic mail and its attachments and destroy any copies which may be in your possession. UCB screens electronic mails for viruses but does not warrant that this electronic mail is free of any viruses. UCB accepts no liability for any damage caused by any virus transmitted by this electronic mail. (Ref: #*CUK0308)
--------------------------------------------------------

  

--
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include TopBraid Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
# Saved by TopBraid on Fri May 14 15:49:41 CDT 2010
# baseURI: http://todel.org/unnamed1
# imports: http://topbraid.org/sparqlmotionlib
# imports: http://rdfs.org/sioc/ns

@prefix :        <http://todel.org/unnamed1#> .
@prefix afn:     <http://jena.hpl.hp.com/ARQ/function#> .
@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sioc:    <http://rdfs.org/sioc/ns#> .
@prefix sm:      <http://topbraid.org/sparqlmotion#> .
@prefix smf:     <http://topbraid.org/sparqlmotionfunctions#> .
@prefix sml:     <http://topbraid.org/sparqlmotionlib#> .
@prefix sp:      <http://spinrdf.org/sp#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

sioc:Item_1
      rdf:type sioc:Item ;
      rdfs:label "Item_1"^^xsd:string .

sioc:Item_2
      rdf:type sioc:Item ;
      rdfs:label "Item_2"^^xsd:string ;
      sioc:follows sioc:Item_1 ;
      owl:differentFrom sioc:Item_1 .

sioc:f
      rdf:type sioc:Item ;
      rdfs:label "f"^^xsd:string .

sioc:forum1
      rdf:type sioc:Usergroup ;
      rdfs:label "forum1"^^xsd:string .

sioc:forum2
      rdf:type sioc:Usergroup ;
      rdfs:label "forum2"^^xsd:string .

sioc:forum3
      rdf:type sioc:Usergroup ;
      rdfs:label "forum3"^^xsd:string .

<http://todel.org/unnamed1>
      rdf:type owl:Ontology ;
      owl:imports <http://rdfs.org/sioc/ns> , 
<http://topbraid.org/sparqlmotionlib> ;
      owl:versionInfo "Created with TopBraid Composer"^^xsd:string .

:ApplyConstruct_1
      rdf:type sml:ApplyConstruct ;
      rdfs:label "Apply construct_1"^^xsd:string ;
      sm:nodeX 373 ;
      sm:nodeY 577 ;
      sml:constructQuery
              [ rdf:type sp:Construct ;
                sp:templates ([ sp:object _:b1 ;
                            sp:predicate rdfs:domain ;
                            sp:subject
                                    [ sp:varName "prop"^^xsd:string
                                    ]
                          ] [ sp:object owl:Class ;
                            sp:predicate rdf:type ;
                            sp:subject _:b1
                          ] [ sp:object
                                    [ sp:varName "domainList"^^xsd:string
                                    ] ;
                            sp:predicate owl:unionOf ;
                            sp:subject _:b1
                          ]) ;
                sp:where ()
              ] .

:ConcatenateText_1
      rdf:type sml:ConcatenateText ;
      rdfs:label "Concatenate text_1"^^xsd:string ;
      sm:next :ConvertTextToRDFList_1 ;
      sm:nodeX 582 ;
      sm:nodeY 319 ;
      sm:outputVariable "text"^^xsd:string ;
      sml:selectQuery
              [ rdf:type sp:Select ;
                sp:resultVariables (_:b2) ;
                sp:where ([ sp:object _:b3 ;
                            sp:predicate rdfs:domain ;
                            sp:subject
                                    [ sp:varName "prop"^^xsd:string
                                    ]
                          ] [ rdf:type sp:Let ;
                            sp:expression
                                    [ rdf:type afn:namespace ;
                                      sp:arg1 _:b3
                                    ] ;
                            sp:variable
                                    [ sp:varName "ns"^^xsd:string
                                    ]
                          ] [ rdf:type sp:Let ;
                            sp:expression
                                    [ rdf:type afn:localname ;
                                      sp:arg1 _:b3
                                    ] ;
                            sp:variable
                                    [ sp:varName "name"^^xsd:string
                                    ]
                          ] [ rdf:type sp:Let ;
                            sp:expression
                                    [ rdf:type smf:buildString ;
                                      sp:arg1 "{?ns}{?name}"
                                    ] ;
                            sp:variable _:b2
                          ])
              ] ;
      sml:separator ","^^xsd:string .

:ConvertTextToRDFList_1
      rdf:type sml:ConvertTextToRDFList ;
      rdfs:label "Convert text to RDFList_1"^^xsd:string ;
      sm:next :ApplyConstruct_1 ;
      sm:nodeX 342 ;
      sm:nodeY 312 ;
      sm:outputVariable "domainList"^^xsd:string .

:ImportCurrentRDF_1
      rdf:type sml:ImportCurrentRDF ;
      rdfs:label "Import current RDF_1"^^xsd:string ;
      sm:next :IterateOverSelect_1 ;
      sm:nodeX 616 ;
      sm:nodeY 15 .

:IterateOverSelect_1
      rdf:type sml:IterateOverSelect ;
      rdfs:label "Iterate over select_1"^^xsd:string ;
      sm:body :ConcatenateText_1 ;
      sm:nodeX 434 ;
      sm:nodeY 161 ;
      sml:selectQuery
              [ rdf:type sp:Select ;
                sp:resultVariables (_:b4) ;
                sp:where ([ sp:object owl:DatatypeProperty ;
                            sp:predicate rdf:type ;
                            sp:subject _:b4
                          ] [ rdf:type sp:Let ;
                            sp:expression
                                    [ rdf:type smf:countResults ;
                                      sp:arg1 "SELECT ?domain WHERE { ?prop 
rdfs:domain ?domain.}"
                                    ] ;
                            sp:variable _:b5
                          ] [ rdf:type sp:Filter ;
                            sp:expression
                                    [ rdf:type sp:gt ;
                                      sp:arg1 _:b5 ;
                                      sp:arg2 1
                                    ]
                          ])
              ] .

:testDomain1
      rdf:type owl:DatatypeProperty ;
      rdfs:domain sioc:Item ;
      rdfs:label "test domain1"^^xsd:string .

:testDomain2
      rdf:type owl:DatatypeProperty ;
      rdfs:domain sioc:Role , sioc:Item ;
      rdfs:label "test domain 2"^^xsd:string .

:testDomain3
      rdf:type owl:DatatypeProperty ;
      rdfs:domain foaf:Document , foaf:Agent , sioc:Container ;
      rdfs:label "test domain 3"^^xsd:string ;
      owl:unionOf
              [ rdf:rest
                        [ rdf:rest ()
                        ]
              ] ;
      owl:unionOf
              [ rdf:rest
                        [ rdf:rest ()
                        ]
              ] .

foaf:person1
      rdf:type foaf:Agent ;
      rdfs:label "person1"^^xsd:string ;
      sioc:follows sioc:forum1 , sioc:forum2 .

foaf:person2
      rdf:type foaf:Agent ;
      rdfs:label "person2"^^xsd:string ;
      sioc:follows sioc:forum2 , sioc:forum3 .

foaf:person3
      rdf:type foaf:Agent ;
      rdfs:label "person3"^^xsd:string ;
      sioc:follows sioc:forum1 , sioc:forum3 ;
      :testDomain3 sioc:Forum .

_:b5  sp:varName "count"^^xsd:string .

_:b4  sp:varName "prop"^^xsd:string .

_:b3  sp:varName "domain"^^xsd:string .

_:b2  sp:varName "domainStr"^^xsd:string .

Reply via email to