Kamis, 10 November 2011

From Natural Language to DL


  • Superheroes that wear bat-costumes have sidekicks.
    $Superhero \sqcap\exists wear.BatCostume \sqsubseteq \exists hasSidekick.\top$
     
  • Someone whose opponent is a superhero is a supervillain.
    $\exists hasOpponent.Superhero \sqsubseteq Supervillain$
     
  • Only superheroes and supervillains can have superpowers.
    $\exists hasSuperpower.\top \sqsubseteq (Superhero \sqcup Supervillain)$
     
  • Someone who has a sidekick also has a teammate.
    $\exists hasSidekick.\top \sqsubseteq \exists hasTeammate.\top$
     
  • A person's sidekick is always that person's teammate.
    $hasSidekick \sqsubseteq hasTeammate$
PS: These were my exercises from the Fuzzy Description Logic course @ TU Dresden.

Jumat, 14 Oktober 2011

Kamis, 21 Juli 2011

RDFa = RDF + awesome



This video is provided by msporny. It's rather old (est. 2008) and is subjected to some specification updates. Here I wanna try to make the vid summary:
  • RDFa = RDF (Resource Description Framework) + awesome
  • Actually, it stands for = RDF in attributes
  • RDFa empowers bloggers and web designers to add semantic information directly to web pages.
  • RDFa is based on RDF.
  • RDF is a concept, not a syntax.
  • There are three things in RDF = subjects + predicates + objects
  • Those three things are usually called triples.
  • RDF uses URIs to specify subjects, predicates, and objects.
  • For instance: Dave likes cookies, becomes, <#dave> <pref:likes> <#cookies>
  • There can be many triples associated with the particular subject.
  • RDFa is a syntax used to describe RDF to computers.
FYI, RDFa attributes are (source):
  • about and src – a URI or CURIE specifying the resource the metadata is about
  • rel and rev – specifying a relationship or reverse-relationship with another resource
  • href and resource – specifying the partner resource
  • property – specifying a property for the content of an element
  • content – optional attribute that overrides the content of the element when using the property attribute
  • datatype – optional attribute that specifies the datatype of text specified for use with the property attribute
  • typeof – optional attribute that specifies the RDF type(s) of the subject (the resource that the metadata is about)

Here comes the conclusion

How the Semantic Web is built? Triple by triple. Triples link to other triples, which then link to more triples. These links go between pages, between blogs, between sites, and between countries. The more triples that are available on the web, the more computers will be able to understand our world.

Hynotized by Fuseki

No, this is indeed not a song title (at least, that's what Mr. Google said!). Basically, what I am trying to do is to build (reuse, to be exact) a federated query server for my project. And thanks God, I've found Fuseki!


But, wait a minute, what's exactly federated query mean? Well, literally, federated query means you send queries over a couple of remote endpoints and then aggregate the query results. I know of two ways to do this by using Named Graphs; and SERVICE keyword, in which I am gonna explore now.

And then? So, assume that I own three companies; Company A, Company B, and Company C. Each of these companies already supports Semantic Web technologies (because they're my companies!), therefore each of them has a SPARQL endpoint for querying datasets. But the problem is, I want to do a query for them all at once, for example, I wanna get a list of employees from my companies, along with their job position. Well, easy peasy then, here's the query:

prefix ex: <http://example.com/ex/0.1/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?role ?companyname
{
?ds ex:endpoint ?ep .
SERVICE ?ep {
?person foaf:name ?name .
?person ex:role ?role .
?person ex:company ?company .
?company foaf:name ?companyname
}
} ORDER BY ASC(?companyname)


But, wait, did you notice that I just utilized a variable for substituting the SERVICE URIs? Yes I did! In order to run that query, I must specify what SERVICE URIs to be queried federately. It means I should write an RDF file containing data about SPARQL endpoints for all my companies, and then load it into my SPARQL server. So, check out the following RDF file then!

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:ex="http://example.com/ex/0.1/">
<ex:Dataset rdf:about="http://a.com/foaf.rdf#dataset">
<ex:endpoint rdf:resource="http://localhost:4040/lab/query"/>
</ex:Dataset>
<ex:Dataset rdf:about="http://b.com/foaf.rdf#dataset">
<ex:endpoint rdf:resource="http://localhost:5050/lab/query"/>
</ex:Dataset>
<ex:Dataset rdf:about="http://c.com/foaf.rdf#dataset">
<ex:endpoint rdf:resource="http://localhost:6060/lab/query"/>
</ex:Dataset>
</rdf:RDF>


OK then, now I could execute my sacred, holy, and precious federated query! After that, I got the following result:


If you're curious what's inside the datasets from each company, check this stuff out then (actually, I concat them all on the code below).

//Company A
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:ex="http://example.com/ex/0.1/">
<foaf:Person rdf:about="http://a.com/foaf.rdf#fariz-darari">
<foaf:name>Fariz Darari</foaf:name>
<foaf:title>Mr</foaf:title>
<ex:company rdf:resource="http://a.com/foaf.rdf#company" />
<ex:role>CEO</ex:role>
</foaf:Person>
<foaf:Person rdf:about="http://a.com/foaf.rdf#syahrini">
<foaf:name>Syahrini</foaf:name>
<foaf:title>Ms</foaf:title>
<ex:company rdf:resource="http://a.com/foaf.rdf#company" />
<ex:role>Secretary</ex:role>
</foaf:Person>
<ex:Company rdf:about="http://a.com/foaf.rdf#company">
<foaf:name>Company A</foaf:name>
</ex:Company>
</rdf:RDF>
//Company B
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:ex="http://example.com/ex/0.1/">
<foaf:Person rdf:about="http://b.com/foaf.rdf#budi-susilo">
<foaf:name>Budi Susilo</foaf:name>
<foaf:title>Mr</foaf:title>
<ex:company rdf:resource="http://b.com/foaf.rdf#company" />
<ex:role>Janitor</ex:role>
</foaf:Person>
<foaf:Person rdf:about="http://b.com/foaf.rdf#gayus">
<foaf:name>Gayus</foaf:name>
<foaf:title>Mr</foaf:title>
<ex:company rdf:resource="http://b.com/foaf.rdf#company" />
<ex:role>Debt Collector</ex:role>
</foaf:Person>
<ex:Company rdf:about="http://b.com/foaf.rdf#company">
<foaf:name>Company B</foaf:name>
</ex:Company>
</rdf:RDF>
//Company C
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:ex="http://example.com/ex/0.1/">
<foaf:Person rdf:about="http://c.com/foaf.rdf#ani">
<foaf:name>Ani</foaf:name>
<foaf:title>Mrs</foaf:title>
<ex:company rdf:resource="http://c.com/foaf.rdf#company" />
<ex:role>CEO</ex:role>
</foaf:Person>
<foaf:Person rdf:about="http://c.com/foaf.rdf#bambang">
<foaf:name>Bambang</foaf:name>
<foaf:title>Mr</foaf:title>
<ex:company rdf:resource="http://c.com/foaf.rdf#company" />
<ex:role>CTO</ex:role>
</foaf:Person>
<ex:Company rdf:about="http://c.com/foaf.rdf#company">
<foaf:name>Company C</foaf:name>
</ex:Company>
</rdf:RDF>

Senin, 30 Mei 2011

SMW ♥ 303

How do I know? Here's the clue. Have a look at the log generated by Live HTTP headers (a Firefox add-on) below:

01: http://localhost/wiki/index.php/Special:URIResolver/Mr_X
02:
03: GET /wiki/index.php/Special:URIResolver/Mr_X HTTP/1.1
04: Host: localhost
05: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
06: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
07: Accept-Language: en-gb,en;q=0.5
08: Accept-Encoding: gzip,deflate
09: Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
10: Keep-Alive: 65535
11: Connection: keep-alive
12: If-Modified-Since: Mon, 30 May 2011 15:02:24 GMT
13:
14: HTTP/1.1 303 See Other
15: Date: Mon, 30 May 2011 15:08:38 GMT
16: Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
17: X-Powered-By: PHP/5.3.5
18: Vary: Accept-Encoding,Cookie
19: Expires: Thu, 01 Jan 1970 00:00:00 GMT
20: Cache-Control: private, must-revalidate, max-age=0
21: Last-Modified: Mon, 30 May 2011 15:08:38 GMT
22: Location: http://localhost/wiki/index.php/Mr_X
23: Content-Length: 0
24: Keep-Alive: timeout=5, max=100
25: Connection: Keep-Alive
26: Content-Type: text/html; charset=utf-8
27: ----------------------------------------------------------
28: http://localhost/wiki/index.php/Mr_X
29:
30: GET /wiki/index.php/Mr_X HTTP/1.1
31: Host: localhost
32: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
33: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
34: Accept-Language: en-gb,en;q=0.5
35: Accept-Encoding: gzip,deflate
36: Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
37: Keep-Alive: 65535
38: Connection: keep-alive
39:
40: HTTP/1.1 200 OK
41: Date: Mon, 30 May 2011 15:08:38 GMT
42: Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
43: X-Powered-By: PHP/5.3.5
44: Content-Language: en
45: Vary: Accept-Encoding,Cookie
46: Expires: Thu, 01 Jan 1970 00:00:00 GMT
47: Cache-Control: private, must-revalidate, max-age=0
48: Last-Modified: Mon, 30 May 2011 16:30:27 GMT
49: Keep-Alive: timeout=5, max=99
50: Connection: Keep-Alive
51: Transfer-Encoding: chunked
52: Content-Type: text/html; charset=UTF-8
53: ----------------------------------------------------------
view raw 303 @ SMW.txt hosted with ❤ by GitHub

So, what does really happen?
  1. I send a request to dereferencing the resource (any kind of resource) URI  @ line 3. I add a content negoitation stuff on the header like line 6.
  2. The server gives a 303 response (yay!) @ line 14 and because I was asking for text/html content, the server gives a redirection to this location @ line 22.
  3. I send a second request  @ line 30 to get the text/html content (information resource) to the location as specified on the server response.
  4. I got a 200 @ line 40, voila! Now I could read the information describing the resource URI.

Jumat, 20 Mei 2011

Silly Semantic

Just exported this RDF file from my Drupal profile page (localhost) and if you look at it, you'll find out why I called this silly.

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:sioc="http://rdfs.org/sioc/ns#">
<rdf:Description rdf:about="http://localhost/drupal/node/4">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
<foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Fariz</foaf:name>
<dc:date rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2011-04-06T23:06:09+07:00</dc:date>
<dc:created rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2011-04-06T23:06:09+07:00</dc:created>
<dc:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2011-04-07T18:23:26+07:00</dc:modified>
<sioc:has_creator rdf:resource="http://localhost/drupal/user/1"/>
<sioc:num_replies rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">0</sioc:num_replies>
<foaf:title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Dr.</foaf:title>
</rdf:Description>
</rdf:RDF>

Hey guys, I was born on 2011-04-06T23:06:09+07:00! I'm a baby then!

PS: This silliness comes when you mix up the semantic about a document and a thing described by that document.

Semantic Web: Intro