store different languages from dbpedia

50 views
Skip to first unread message

haklaekim

unread,
Jun 21, 2012, 9:52:14 PM6/21/12
to arc-dev
Hi,

I have extracted data from dbpedia. I would like to store all
different languages such as "abstracts of a certain resource" or
values of rdfs:label.
The following code is supposed to extract english version one of
different languages.
If there are different languages, how do I store them by the
languages?
Probably, I need to remove FILTER option, then make some codes (have
no idea).

Best,
Haklae

/* Create the 'remote store' */
$dbpedia = ARC2::getRemoteStore($dbpconfig);

/* abstract */
$strAbstract = "
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT ?abstract
WHERE
{ <$dbpuri> dbpedia-owl:abstract ?abstract .
FILTER ( langMatches(lang(?abstract), \"EN\") )
}
";
$dbpAbstract = $dbpedia->query($strAbstract, 'row');

Keith Alexander

unread,
Jun 22, 2012, 2:30:55 AM6/22/12
to arc...@googlegroups.com
Hi Haklae,

Yes, if you want to query for an abstract in a different language,
simply change EN to another two letter language code (eg, FR for
French).
If you remove the FILTER ( langMatches(lang(?abstract), \"EN\") )
altogether, you will get the abstract in all available languages, and
you can examine the results to see what language codes are used.

If you want to match a precise language code in the data (eg: en-gb is
British English), your filter can be like:

FILTER(lang(?abstract)="en-gb")

however if you want to match any variant of a language (in this case,
English), you can use langMatches:

FILTER( langMatches(lang(?abstract), "EN") )

(this will match literals with languages including en-gb, en-us, en,
en-ca, en-au)

for further details see
http://www.w3.org/TR/rdf-sparql-query/#matchLangTags
and
http://www.w3.org/TR/rdf-sparql-query/#func-langMatches


HTH

Keith

Kim Haklae

unread,
Jun 24, 2012, 9:33:07 AM6/24/12
to arc...@googlegroups.com
Hi Keith,

Thanks for your response. I might gather all abstracts of a certain uri.
Once I get the data, how can it be extracted by languages? 
The following code does not satisfy two conditions. Could you help me?

Thanks,
Haklae.

$q = "
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?abstract
WHERE
 { <$uri> dbpedia-owl:abstract ?abstract . }
";
$abstract = $dbpedia->query($q, 'rows');

  foreach ($abstract as $object)
  {
  echo $object['abstract'] . "<br />";   
--
Dr.Dr. Haklae Kim
Senior Engineer
Service Platform Group
Media Solution Center, DMC
Samsung Electronics, Co. Ltd.
Tel: +82-(0)10-3201-0714
Who's Who in the World's 27th Edition - 2010

Reply all
Reply to author
Forward
0 new messages