combining 2 value in ARC

25 views
Skip to first unread message

Dhira P. Yuga

unread,
May 16, 2012, 4:22:51 AM5/16/12
to arc-dev
Hello,
I have data like this,
bookTitle "book one", hasAuthor "author A" and "author B".

if I select normally it will has result
hasAuthor | bookTitle
"author A" | "book one"
"author B" | "book one"

what i want is
hasAuthor | bookTitle
"author A", "author B" | "book one"

any tips and tricks or something that can solve my problem?


Thanks,

Dhira

Keith Alexander

unread,
May 16, 2012, 4:40:32 AM5/16/12
to arc...@googlegroups.com
Would a DESCRIBE or CONSTRUCT query instead of a SELECT work for you?
eg:

DESCRIBE ?book WHERE
{
?book ex:bookTitle ?title ;
ex:hasAuthor ?author .
}
LIMIT 20

This would return you a "resource index" (see [1]), like
array(
BookOneUri => array(
ex:bookTitle => array( "some title" ),
ex:hasAuthor => array("author one", "author two"),
)
)

With DESCRIBE, you get back all the triples about the book, with
CONSTRUCT, you can choose which triples you want back.

A CONSTRUCT query would look like:

CONSTRUCT
{
?book ex:bookTitle ?title ;
ex:hasAuthor ?author .
}
WHERE
{
?book ex:bookTitle ?title ;
ex:hasAuthor ?author .
}
LIMIT 20

And will return the same kind of nested associative array structure as
the DESCRIBE.

HTH

Keith


[1] https://github.com/semsol/arc2/wiki/Internal-Structures

Dhira P. Yuga

unread,
May 16, 2012, 5:02:59 AM5/16/12
to arc...@googlegroups.com
I use store like this $rows = $store->query($query, 'rows').
i want select that data and display that on web browser.

in the OWL, the author is related to class author.
class book has bookTitle and isTitleOf
class author has authorName and hasTitle

isTitleOf and hasTitle has functional and inverseFunctional relation.
in data with bookTitle "book one" has 2 value ID from class author in isTitleOf.

if i select, it wil display 2 title "book one" with 2 different author, 
what i want is it display just one title "book one" but with 2 author names.

thanks

Dhira

Keith Alexander

unread,
May 16, 2012, 6:09:10 AM5/16/12
to arc...@googlegroups.com
On Wed, May 16, 2012 at 10:02 AM, Dhira P. Yuga <d18....@gmail.com> wrote:
> I use store like this $rows = $store->query($query, 'rows').
> i want select that data and display that on web browser.
>

If the books can have an arbitrary number of authors, and you don't
want more than one row per book, you need to do a DESCRIBE or
CONSTRUCT and create the table yourself:

<?php
$index = $store->query($yourDescribeQuery, 'raw');
$titleP = '';// the uri of your hasTitle predicate
$authorP = '';// the uri of your hasAuthor predicate
?>
<table>
<?php foreach($index as $uri => $props):?>
<tr>
<td><?php echo $props[$titleP][0]?></td>
<td><?php echo implode(', ', $props[$authorP])?></td>
</tr>
<?php endforeach ?>
</table>

Cheers

Keith
Reply all
Reply to author
Forward
0 new messages