⬆️ ⬇️

FOAF and example

FOAF (English Friend of a Friend) - a project to create a model of agent-readable home pages and social networks. Founders Libby Miller and Dan Brickley. The basis of the project is a specification that defines some expressions used in statements (eng. Statements) about someone: for example, name, gender and other characteristics. This is for those who do not know what it is, but on Habré they wrote about it, but without a practical example.



For the example of working with the FOAF user page we will use LAMP. For easy work with FOAF, you can use the ARC library, which helps you very quickly and easily manipulate rdf data and make sparql queries. Also this library is often advised by the author of books on the Semantic Web abroad.



For example, create your own FOAF page:



test.rdf

<rdf:RDF

xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

xmlns:foaf="http://xmlns.com/foaf/0.1/"

xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">

<foaf:Person>

<foaf:name>Dima Kalinin</foaf:name>

<foaf:mbox rdf:resource="mailto:kal1sha.ua@gmail.com"/>

<foaf:homepage rdf:resource="http://twitter.com/kal1sha" />

<foaf:nick>kal1sha</foaf:nick>

<foaf:depiction rdf:resource="http://a1.twimg.com/profile_images/596994746/17752844_bigger.gif" />

<foaf:interest>

<rdf:Description rdf:about="http://habrahabr.ru/" rdfs:label="Habrahabr" />

</foaf:interest>

<foaf:knows>

<foaf:Person>

<foaf:name>Dima Kulish</foaf:name>

<foaf:name>Konstanit Gancov</foaf:name>

</foaf:Person>

</foaf:knows>

</foaf:Person>

</rdf:RDF>



')

I think the description for it will be superfluous, since rdf is a branch of xml and also does not need a great knowledge of English to understand what is described.



Here is an example of how to display all the names in the profile file:

test.php

<?php

include_once("./ARC2.php");



//

$config = array(

'db_name' => 'foaf',

'db_user' => 'root',

'db_pwd' => '1234',

'store_name' => 'arc_tests',

'max_errors' => 100,

);

//

$store = ARC2::getStore($config);

if (!$store->isSetUp()) {

$store->setUp();

}

//, rdf

$parser = ARC2::getRDFParser();

$parser->parse('test.rdf');

$triples = $parser->getTriples();



// , mysql

$parser = ARC2::getRDFParser();

$parser->parse('./test.rdf');

//

$store->query('LOAD <./test.rdf>');

$triples = $parser->getTriples();



// ,

//

$q = '

PREFIX foaf: <xmlns.com/foaf/0.1> .

SELECT ?person ?name WHERE {

?person a foaf:Person ; foaf:name ?name .

}

';

$r = '';

if ($rows = $store->query($q, 'rows')) {

foreach ($rows as $row) {

$r .= '' . $row['name'] . '';

}

}



echo $r ? '' : ' ';

?>





Displays:

Dima Kalinin

Dima kulish

Konstantin Gancov

Source: https://habr.com/ru/post/83560/



All Articles