You should be able to avoid using unions by creating a common parent class
for Part, Section, etc. Then instead of something like
?class rdfs:subClassOf :Part .
?part a ?class ;
Do
?class rdfs:subClassOf* :ParentClass .
?item a ?class ;
And then put each of the level specific patterns into the optional clauses.
I don't have enough information to know whether this will optimize
performance for you.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scott Henninger
Sent: Friday, June 04, 2010 11:19 AM
To: TopBraid Suite Users
Subject: [topbraid-users] Re: Optimization of Sparql Query
John; It's generally pretty difficult to know how a query can be
refactored when sample data isn't available. However one thing you
may try is using SPIN functions to abstract out some of the common
patterns you have. For example, it seems the following is a common
graph pattern in your union statements:
SELECT ?asection
{
?arg1 :hasPartNumber ?partnumber ;
:hasChapterNumber ?chapternumber ;
:hasSectionNumber ?asection ;
}
For writing a SPIN function, see the FAQ at
http://www.topquadrant.com/products/TBS_FAQ.html#TBS2,
which pints to a blog and tutorial on SPIN functions.
You might also want to look into your model to see if using a
Composite pattern (different kind of pattern - a design pattern in
this case) for representing the child/parent relationships in your
document. There is a composite model in TBC - TopBraid/TBC/
composite.owl. Changing the model some may make your queries easier
to manage and quicker to process.
-- Scott
On Jun 4, 5:28 am, John Perdoni <[email protected]> wrote:
> Firstly, i apologise if this is off forum, but if possible, seing as i
> not nearly fluent enough in sparql as of yet, I was wondering if there
> was a way to optimize this query seeing as a lot of the statements are
> repeated.
>
> thanks in advance again for your continued support
>
> John
>
> SELECT ?partheading ?chapterheading ?Regulation ?sectionheading ?
> SubRegulation ?subsectionheading ?secondsubsection
> WHERE {
> { ?class rdfs:subClassOf :Part .
> ?part a ?class ;
> :hasPartNumber ?partnumber ;
> :hasHeading ?partheading}
>
> UNION
> { ?class1 rdfs:subClassOf :Chapter .
> ?chapter a ?class1 ;
> :hasPartNumber ?partnumber ;
> :hasChapterNumber ?chapternumber;
> :hasHeading ?chapterheading .
> }
> UNION
> { ?class2 rdfs:subClassOf :Section .
> ?section a ?class2 ;
> :hasPartNumber ?partnumber ;
> :hasChapterNumber ?chapternumber ;
> :hasSectionNumber ?sectionnumber ;
> :hasHeading ?sectionheading .
> OPTIONAL {?section :hasRegulationNumber ?Regulation}.
> }
> UNION
> { ?class3 rdfs:subClassOf :SubSection .
> ?subsection a ?class3 ;
> :hasPartNumber ?partnumber ;
> :hasChapterNumber ?chapternumber ;
> :hasSectionNumber ?sectionnumber;
> :hasSubSectionNumber ?subsectionnumber ;
> :hasHeading ?subsectionheading ;
> OPTIONAL {?subsection :hasRegulationNumber ?SubRegulation}.
> }
> UNION
> { ?class4 rdfs:subClassOf :SecondSubSection .
> ?secondsubsection a ?class4 ;
> :hasPartNumber ?partnumber ;
> :hasChapterNumber ?chapternumber ;
> :hasSectionNumber ?sectionnumber;
> :hasSubSectionNumber ?subsectionnumber ;
> :hasSecondSubSectionNumber ?secondsubsectionnumber ;
> OPTIONAL {?secondsubsection :hasRegulationNumber ?SubReg }.
> }
> UNION
> { ?class5 rdfs:subClassOf :ThirdSubSection .
> ?thirdsubsection a ?class5 ;
> :hasPartNumber ?partnumber ;
> :hasChapterNumber ?chapternumber ;
> :hasSectionNumber ?sectionnumber;
> :hasSubSectionNumber ?subsectionnumber ;
> :hasSecondSubSectionNumber ?secondsubsectionnumber;
> :hasThirdSubSectionNumber ?thirdsubsectionnumber.
> }}
>
> ORDER by ?partnumber ?chapternumber ?sectionnumber ?subsectionnumber ?
> secondsubsectionnumber
--
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
--
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