hello if we have this data

Apple_iPhone_5  type    CNews
Apple_iPhone_5  date    21/12/2012 12:00:00 AM
Apple_iPhone_5  fromArea    Berlin                  *the city*
Apple_iPhone_5  heading        Apple iPhone 5
Apple_iPhone_5  inCategory  Technology
Apple_iPhone_5  tags    Apple iPhone5
Apple_iPhone_5  text    iPhone 5 Price is $200

after inference by construct three triples add to graph

Apple_iPhone_5  inCategory  GeneralCategory             *the main category*
Apple_iPhone_5  fromArea    Europe                      *the region*  
Apple_iPhone_5  fromArea    Germany                     *the country*

the sparql select return return 6 rows for Apple_iPhone_5 that is because property inCategory have 2 value Property fromarea have 3 value 2*3 = 6

this is the query

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX base: <http://www.owl-ontologies.com/news.owl#>
      ?CNews rdf:type base:CNews  .
      ?CNews base:inCategory ?Category .
     ?CNews base:text ?text .
     ?CNews base:date ?date .
     ?CNews base:heading ?heading .
     ?CNews base:tags ?tags .
     ?CNews base:aboutEvent ?aboutEvent .
     ?CNews base:fromArea ?fromArea. }

how can i prevent this redundancy in data

asked 19 Feb '13, 16:13

mhdeyad's gravatar image

accept rate: 0%

What SPARQL engine are you using? It could be possible to turn off inference if you don't need the inferred triples.

(20 Feb '13, 06:14) utapyngo utapyngo's gravatar image

@utapyngo I think the question says the inference is done manually via a CONSTRUCT query

(20 Feb '13, 12:17) Rob Vesse ♦ Rob%20Vesse's gravatar image

that is right the inference is done manually via a CONSTRUCT query Because when i query for news from Continent like Europe or Country Like Germany , i got a result, as well as query by category like Technology or GeneralCategory. but i want the result show the original data without redundancy, for example query for news about Europe the result :

?CNews =Apple_iPhone_5 ?Category =Technology ?text =iPhone 5 Price is $200 ?date =21/12/2012 12:00:00 AM ?heading =Apple iPhone 5 ?tags =Apple iPhone5 ?aboutEvent = General ?fromArea =Berlin

(20 Feb '13, 17:26) mhdeyad mhdeyad's gravatar image

You can 'prevent' this 'redundancy' in several ways.

One way is to just adapt your SELECT clause: only select those variables where there are no double values expected for a given subject, and then do separate queries for the other values:

SELECT DISTINCT ?CNews ?text ?date ?heading ?aboutEvent

Another way to reduce the number of result rows is to use a GROUP_CONCAT function (this is SPARQL 1.1):

   SELECT DISTINCT ?CNews ?text ?date ?heading ?aboutEvent (GROUP_CONCAT(?category) as ?cats) (GROUP_CONCAT(?fromArea) as ?areas)
   WHERE { ... }
   GROUP BY ?CNews ?text ?date ?heading ?aboutEvent

Yet another way is to use subqueries to only retrieve one value for each given item:

  WHERE {  ?CNews a base:CNews .
           { SELECT ?category 
             WHERE { ?CNews base:inCategory ?category }
             LIMIT 1

There probably other varieties of the above suggestions you can use (I can imagine you could combine the GROUP_CONCAT with a subquery, instead of setting a limit).

You can also choose to use a CONSTRUCT query instead of a SELECT, so that your result will be in the form of a subgraph which you can then pick apart.

By far the simplest way to deal with it, however, is to just accept that when something has multiple values for a certain property, you will get partially-duplicate solutions in your query result, and just to keep that in mind when processing your result.

permanent link

answered 19 Feb '13, 18:26

Jeen%20Broekstra's gravatar image

Jeen Broekstra ♦
accept rate: 37%

Use a separator in the GROUP_CONCAT, otherwise the result will look terrible.

(23 Feb '13, 08:03) Antoine Zimm... ♦ Antoine%20Zimmermann's gravatar image

The default separator is a white space. YMMV on how terrible that is...

(23 Feb '13, 15:27) Jeen Broekstra ♦ Jeen%20Broekstra's gravatar image

i try this, but there is no data appear in last tow column ?cats,areas ! : SELECT DISTINCT ?CNews ?text ?date ?heading ?aboutEvent (GROUP_CONCAT(?category) as ?cats) (GROUP_CONCAT(?fromArea ) as ? areas) WHERE { ?CNews rdf:type base:CNews . ?CNews base:inCategory ?category . ?CNews base:text ?text . ?CNews base:date ?date . ?CNews base:heading ?heading . ?CNews base:tags ?tags . ?CNews base:aboutEvent ?aboutEvent . ?CNews base:fromArea ?fromArea. ?fromArea rdf:type base:CCity . } GROUP BY ?CNews ?text ?date ?heading ?aboutEvent

(24 Feb '13, 19:20) mhdeyad mhdeyad's gravatar image

Dear Jeen ,thanks for your Answer :

i like your Select which contain Group_Concat, but the last tow column

(?cats,?areas) have not any value, i expect to see many value in it separated with white space? .... any help

(25 Feb '13, 10:48) mhdeyad mhdeyad's gravatar image

hello can any body help me, its urgent ?

just i want why Group_Concat column return only (,,,,,,) and no data between comma .

note: i use dotnetrdf library

(09 Mar '13, 16:47) mhdeyad mhdeyad's gravatar image

It's urgent? Oohh... You should know that answering here is voluntary! Not a very helpful comment, I know.

(10 Mar '13, 12:15) AKSWMember AKSWMember's gravatar image

@mhdeyad The answer you have here answers your question as it is, if you have a different question ask it as a different question and provide enough information for people to answer it

(11 Mar '13, 12:11) Rob Vesse ♦ Rob%20Vesse's gravatar image
showing 5 of 7 show 2 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 19 Feb '13, 16:13

question was seen: 2,714 times

last updated: 11 Mar '13, 12:11