Friday, 9 August 2013

knowledge base, and a query, write a parser

knowledge base, and a query, write a parser

Given a directed labelled graph in form of a knowledge base, and a query,
write a parser which can return the edges and/or nodes requested in the
query. (Knowledge base and queries are not case sensitive) Knowledge base
is given as input in a text file (input.txt). For example a DAG can be
represented as:
And the corresponding knowledge base for this DAG is :
(<Shelden>, <hasFriend>, <Raj>)
(<Shelden>, <hasFriend>, <Leonard>)
(<Shelden>, <worksAt>, <Caltech>)
(<Leonard>, <worksAt>, <Caltech>)
(<Raj>, <worksAt>, <Caltech>)
(<Raj>, <age>,"30")
[Here 30 is a number and no edge can go out from this node while others
like Nabraska, New_Delhi are entities, which can have further outgoing
links.]
(<Leonard>, <hasFriend>, <Penny>)
(<Penny>, <bornIn>, <Nabraska>)
(<Raj>, <bornIn>, <New_Delhi>)
A query can be written as :
Find persons who are friends?
Test case 1 : Select ?person1 ?person2 where { ?person1 <hasfriend>
?person2. }
The goal is to fill all the variable represented by ? with their values
from knowledge base and return in csv format:
The result of this query is:
Person 1 Person 2
Shelden Raj
Shelden Leonard
Leonard Penny
The similar query can be extended to have joins also:
Find persons who are friends with Sheldon and the company/colleges to
which his friends belong?
Test Case 2 : Select ?person ?university where { <Sheldon> <hasFriend>
?person . ?person <worksAt> ?university. }
Person University
Leonard Caltech
Raj Caltech
Test Case 3 : Select ?person1 ?person2 where { ?person1 <worksAt>
<Caltech> . ?person2 <bornIn < Nabraska> . ?person1 <hasFriend> ?person2
.}
Person 1 Person 2
Leonard Penny
Test Case 5 : select * where {}
Output : Parse Error
How to approach this problem?

No comments:

Post a Comment