<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title>True Knowledge - Blog</title>
<link>http://blog.trueknowledge.com/</link>
<description>Everything about True Knowledge, the company, its products and technology.</description>
<language>en-GB</language>
<lastBuildDate>Tue, 22 Sep 2009 16:20:33 +0100</lastBuildDate>
<generator>http://www.typepad.com/</generator>

<docs>http://www.rssboard.org/rss-specification</docs>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/TrueKnowledgeBlog" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
<title>Calling the True Knowledge API using Javascript</title>
<link>http://blog.trueknowledge.com/2009/09/calling-the-true-knowledge-api-using-javascript.html</link>
<guid isPermaLink="true">http://blog.trueknowledge.com/2009/09/calling-the-true-knowledge-api-using-javascript.html</guid>
<description>A very common question we receive from our API users is how to call the True Knowledge API using Javascript/AJAX. The short answer: you don't call the API directly using Javascript, but you can call it indirectly. This post explains...</description>
<content:encoded>&lt;p&gt;A very common question we receive from our API users is how to call the True Knowledge API using Javascript/AJAX.&lt;/p&gt;

&lt;p&gt;The short answer: you don't call the API directly using Javascript, but you can call it indirectly. This post explains why and how to do so.&lt;/p&gt;

&lt;h2&gt;Why not&lt;/h2&gt;

&lt;p&gt;The reason for not calling the API directly is because the URL call contains your API account credentials, namely your username and API &amp;quot;password&amp;quot; (the API key if you will). If you embed this information into a web page so that it can call the API directly using Javascript, you will be exposing these credentials: anyone can then find your account details.&lt;/p&gt;

&lt;p&gt;Another complication: our API currently outputs only XML, which is not the most Javascript-friendly output.&lt;/p&gt;

&lt;h2&gt;Solution&lt;/h2&gt;
&lt;p&gt;So what to do? Proxy the calls via a server-side script on your website. The server-side script, would be written in PHP or Python or your programming language of choice. It will accept, via a query string variable, the actual search, process it, and then return the results to the Javascript.&lt;/p&gt;

&lt;p&gt;In detail:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the server side-script; let's call this script tk.php and let's say it is hosted on your website at http://example.com/tk.php. We'll talk about the exact contents of tk.php in a second.&lt;/li&gt;
&lt;li&gt;Using jQuery or any other way to do the AJAX call, request tk.php. For example, if the Javascript wants to call the True Knowledge API to ask &amp;quot;what is the capital of France&amp;quot;, the AJAX call could be to:
&lt;p&gt;&lt;code&gt;http://example.com/tk.php?input=what+is+the+capital+of+france&lt;/code&gt;&lt;/p&gt;Here, we're using the query string variable &amp;quot;input&amp;quot; to pass the search to tk.php&lt;/li&gt;
&lt;li&gt;Wait for tk.php to call the True Knowledge API and display its output in the page. The exact details of this vary by how you are doing the AJAX call, and most Javascript frameworks like jQuery and Prototype give you an easy way to embed AJAX output into a web page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;What happens on the server&lt;/h2&gt;
&lt;p&gt;We already have an excellent starting point for tk.php: it is the da.php example in our &lt;a href="http://www.trueknowledge.com/api/"&gt;API PHP library&lt;/a&gt;. What we want here is an even simpler version of this file, so we're going to strip it down.&lt;/p&gt;

&lt;p&gt;The da.php file calls our Direct Answer API service, which is the easiest to work with for this example. You can certainly build more complicated API calls using a True Knowledge Query API call as detailed in the tkquery.php file in the library examples folder.&lt;/p&gt;

&lt;p&gt;The first task is to get rid of the HTML page formatting because the output is going to be embedded into a pre-existing HTML page.&lt;/p&gt;

&lt;p&gt;Secondly, you need to decide if you would like the AJAX output to (potentially) show any errors. In the code below, I've commented out anything that does not display a search result.&lt;/p&gt;

&lt;p&gt;You'll notice that the code below is printing everything the API returned without any real formatting and basic HTML markup. Of course customize this to your needs.&lt;/p&gt;

&lt;p&gt;And with all this said, below is the full code for the tk.php proxy for your AJAX calls.&lt;/p&gt;

&lt;div style="overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="margin: 0"&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin: 0"&gt;&lt;span style="color: #4c8317"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style="color: #00aaaa"&gt;define&lt;/span&gt;(&lt;span style="color: #aa5500"&gt;&amp;#39;API_DIRECTORY&amp;#39;&lt;/span&gt;, &lt;span style="color: #00aaaa"&gt;dirname&lt;/span&gt;(&lt;span style="color: #0000aa"&gt;__FILE__&lt;/span&gt;) . &lt;span style="color: #aa5500"&gt;&amp;#39;/..&amp;#39;&lt;/span&gt;);
&lt;span style="color: #00aaaa"&gt;define&lt;/span&gt;(&lt;span style="color: #aa5500"&gt;&amp;#39;API_ACCOUNT_ID&amp;#39;&lt;/span&gt;, &lt;span style="color: #aa5500"&gt;&amp;#39;&amp;#39;&lt;/span&gt;);
&lt;span style="color: #00aaaa"&gt;define&lt;/span&gt;(&lt;span style="color: #aa5500"&gt;&amp;#39;API_ACCOUNT_PW&amp;#39;&lt;/span&gt;, &lt;span style="color: #aa5500"&gt;&amp;#39;&amp;#39;&lt;/span&gt;);

&lt;span style="color: #0000aa"&gt;if&lt;/span&gt;(&lt;span style="color: #00aaaa"&gt;isset&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$_GET&lt;/span&gt;[&lt;span style="color: #aa5500"&gt;&amp;#39;input&amp;#39;&lt;/span&gt;]))
{
	&lt;span style="color: #aaaaaa; font-style: italic"&gt;//You should sanitize the input as necessary for your application.&lt;/span&gt;
	&lt;span style="color: #aa0000"&gt;$query&lt;/span&gt; = &lt;span style="color: #aa0000"&gt;$_GET&lt;/span&gt;[&lt;span style="color: #aa5500"&gt;&amp;#39;input&amp;#39;&lt;/span&gt;];
}
&lt;span style="color: #0000aa"&gt;if&lt;/span&gt;(&lt;span style="color: #00aaaa"&gt;is_string&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$query&lt;/span&gt;) &amp;amp;&amp;amp; &lt;span style="color: #00aaaa"&gt;strlen&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$query&lt;/span&gt;) &amp;gt; &lt;span style="color: #009999"&gt;0&lt;/span&gt;)
{
	&lt;span style="color: #0000aa"&gt;require_once&lt;/span&gt;(API_DIRECTORY.&lt;span style="color: #aa5500"&gt;&amp;#39;/api.php&amp;#39;&lt;/span&gt;);
	&lt;span style="color: #aa0000"&gt;$request&lt;/span&gt; = &lt;span style="color: #0000aa"&gt;new&lt;/span&gt; KnowledgeEngineDirectAnswerRequest(); 
	
	&lt;span style="color: #aa0000"&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;setAccountId&lt;/span&gt;(API_ACCOUNT_ID);
	&lt;span style="color: #aa0000"&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;setAccountPassword&lt;/span&gt;(API_ACCOUNT_PW);

	&lt;span style="color: #0000aa"&gt;try&lt;/span&gt; {
		&lt;span style="color: #aa0000"&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;setQuery&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$query&lt;/span&gt;);
		&lt;span style="color: #aa0000"&gt;$response&lt;/span&gt; = &lt;span style="color: #aa0000"&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;execute&lt;/span&gt;();
		&lt;span style="color: #0000aa"&gt;if&lt;/span&gt;(&lt;span style="color: #00aaaa"&gt;strlen&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$response&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getErrorCode&lt;/span&gt;()) &amp;gt; &lt;span style="color: #009999"&gt;0&lt;/span&gt;)
    {
			&lt;span style="color: #aaaaaa; font-style: italic"&gt;//NOTE: for this example, we are hiding any errors&lt;/span&gt;
			&lt;span style="color: #aaaaaa; font-style: italic"&gt;//echo &amp;quot;&amp;lt;p&amp;gt;Error for query (&amp;quot;.$query.&amp;quot;):&amp;lt;/p&amp;gt;&amp;quot;;&lt;/span&gt;
			&lt;span style="color: #aaaaaa; font-style: italic"&gt;//echo &amp;quot;&amp;lt;p&amp;gt;&amp;quot;.$response-&amp;gt;getErrorCode().&amp;quot; &amp;quot;.$response-&amp;gt;getErrorMessage().&amp;quot;&amp;lt;/p&amp;gt;&amp;quot;;&lt;/span&gt;
    } &lt;span style="color: #0000aa"&gt;else&lt;/span&gt; {
			&lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;p&amp;gt;Answer for &amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$query&lt;/span&gt;.&lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;;
      &lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;p&amp;gt;&amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$response&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getTextResult&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;/p&amp;gt;&amp;lt;hr/&amp;gt;&amp;quot;&lt;/span&gt;;
			&lt;span style="color: #0000aa"&gt;if&lt;/span&gt; (&lt;span style="color: #aa0000"&gt;$results&lt;/span&gt; = &lt;span style="color: #aa0000"&gt;$response&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getResults&lt;/span&gt;())
      {
				&lt;span style="color: #0000aa"&gt;foreach&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$results&lt;/span&gt; &lt;span style="color: #0000aa"&gt;as&lt;/span&gt; &lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;)
        {
					&lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;p&amp;gt;True Knowledge ID: &amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getId&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;;
					&lt;span style="color: #0000aa"&gt;if&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getOfficialWebSite&lt;/span&gt;())
          {
						&lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;p&amp;gt;Official website: &amp;lt;a href=\&amp;quot;&amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getOfficialWebSite&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getOfficialWebSite&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;;
          }
					&lt;span style="color: #0000aa"&gt;if&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getWikiPage&lt;/span&gt;())
          {
						&lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;p&amp;gt;Wikipedia page: &amp;lt;a href=\&amp;quot;&amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getWikiPage&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;\&amp;quot;&amp;gt;&amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getWikiPage&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;;
          }
					&lt;span style="color: #0000aa"&gt;if&lt;/span&gt;(&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getImage&lt;/span&gt;())
          {
						&lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;p&amp;gt;Image: &amp;lt;img src=\&amp;quot;&amp;quot;&lt;/span&gt;.&lt;span style="color: #aa0000"&gt;$result&lt;/span&gt;-&amp;gt;&lt;span style="color: #1e90ff"&gt;getImage&lt;/span&gt;().&lt;span style="color: #aa5500"&gt;&amp;quot;\&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;&amp;quot;&lt;/span&gt;;
          }
					&lt;span style="color: #0000aa"&gt;echo&lt;/span&gt; &lt;span style="color: #aa5500"&gt;&amp;quot;&amp;lt;hr/&amp;gt;&amp;quot;&lt;/span&gt;;
        }
  		}
		}
	}
	&lt;span style="color: #0000aa"&gt;catch&lt;/span&gt; ( Exception &lt;span style="color: #aa0000"&gt;$ex&lt;/span&gt;)
  {
		&lt;span style="color: #aaaaaa; font-style: italic"&gt;//NOTE: for this example, we are hiding any errors&lt;/span&gt;
		&lt;span style="color: #aaaaaa; font-style: italic"&gt;//echo $ex-&amp;gt;getMessage();&lt;/span&gt;
  }
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content:encoded>



<dc:creator>Pierre Far</dc:creator>
<pubDate>Tue, 22 Sep 2009 16:20:33 +0100</pubDate>

</item>
<item>
<title>True Knowledge Partners with Omgili</title>
<link>http://blog.trueknowledge.com/2009/09/true-knowledge-partners-with-omgili.html</link>
<guid isPermaLink="true">http://blog.trueknowledge.com/2009/09/true-knowledge-partners-with-omgili.html</guid>
<description>We are really pleased to let everyone know about another exciting True Knowledge API partner, Omgili. Omgili, a VC backed search start-up that focuses on “many to many” user generated content platforms, such as forums, discussion groups, answer boards and...</description>
<content:encoded>&lt;p&gt;We are really pleased to let everyone know about another exciting True Knowledge API partner, &lt;a href="http://omgili.com/"&gt;Omgili&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Omgili, a VC backed search start-up that focuses on “many to many” user generated content platforms, such as forums, discussion groups, answer boards and other sources, has integrated True Knowledge results into their &lt;a href="http://google.omgili.com/"&gt;Google@Omgili service&lt;/a&gt;. It is a fantastic example of how True Knowledge can be combined with other search methods to help provide a truly superior search experience, as shown in the &lt;a href="http://google.omgili.com/search?q=president+of+france+in+2009&amp;service=0"&gt;example search for &amp;quot;president of france in 2009&amp;quot;&lt;/a&gt; screenshot below.&lt;/p&gt;

&lt;p&gt;&lt;a style="display: inline;" href="http://trueknowledge.typepad.com/.a/6a00e54f8a936688340120a56374d1970b-pi"&gt;&lt;img class="at-xid-6a00e54f8a936688340120a56374d1970b" alt="Omgili-example" title="Omgili-example" src="http://trueknowledge.typepad.com/.a/6a00e54f8a936688340120a56374d1970b-800wi" border="0"  /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google@Omgili brings together knowledge-based responses powered by True Knowledge and Google search results and it combines theses with their ability to find forum discussions about the results Google returns. With this combination, you can get direct answers to your questions, and you can find people interested in the same topics as you as well as finding more in depth discussions about the subject you are researching.&lt;/p&gt;
</content:encoded>



<dc:creator>Pierre Far</dc:creator>
<pubDate>Fri, 11 Sep 2009 12:02:02 +0100</pubDate>

</item>
<item>
<title>Organizing the World's Knowledge: The True Knowledge Ontology - Part I</title>
<link>http://blog.trueknowledge.com/2009/09/organizing-the-worlds-knowledge-the-true-knowledge-ontology-part-i.html</link>
<guid isPermaLink="true">http://blog.trueknowledge.com/2009/09/organizing-the-worlds-knowledge-the-true-knowledge-ontology-part-i.html</guid>
<description>At the heart of the True Knowledge semantic technology is our ontology. Our ontology describes a tree-like structure of classes, and every entity fits into this tree. In this post I'm going to explain a bit more about how we...</description>
<content:encoded>&lt;p&gt;At the heart of the True Knowledge semantic technology is our ontology. Our ontology describes a tree-like structure of classes, and every entity fits into this tree.&lt;/p&gt;

&lt;p&gt;In this post I'm going to explain a bit more about how we structure the world's information and how you can tap into this structure using our API.&lt;/p&gt;

&lt;p&gt;But first, some theory. Don't skip it because it directly affects how you query the True Knowledge API!&lt;/p&gt;

&lt;h2&gt;What is a Class?&lt;/h2&gt;
&lt;p&gt;The easiest way to explain a class is take a real world example. Below is an image showing the class [book].&lt;/p&gt;

&lt;p&gt;&lt;a href="http://trueknowledge.typepad.com/.a/6a00e54f8a936688340120a5608a76970b-pi"&gt;&lt;img class="at-xid-6a00e54f8a936688340120a5608a76970b" alt="Book Ontology" title="Book Ontology" src="http://trueknowledge.typepad.com/.a/6a00e54f8a936688340120a5608a76970b-800wi" border="0" style="margin: 0px 5px 5px 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our ontology, the class called &lt;a href="http://www.trueknowledge.com/p/book"&gt;[book]&lt;/a&gt; describes all books. It is the collection of all books that we know about, and it will be the home of all books we don't know about when they are added. All books have similar properties and attributes, and all of them can be described in similar terms: If I ask you to imagine what a book is, your mind will picture something similar to what other people imagine a book to be. In short, if you can say &amp;quot;This is a &amp;lt;something&amp;gt;&amp;quot;, that something is a class.&lt;/p&gt;

&lt;p&gt;We know there are different types of books, like novels, cookbooks, art books, textbooks, science books, science fiction books, etc. These are all subclasses of the class [book]. A subclass is a more specific class, and so is lower down in the ontology tree.&lt;/p&gt;

&lt;p&gt;Of course it works the other way too: a more general class is a parent class. So the parent class of [science book] and [cookbook] is [book]. The class [book] itself has two parent classes, [written publication] and [source of knowledge]. The class [written publication] has other subclasses such as [comic], [issue of a periodical], etc.&lt;/p&gt;

&lt;p&gt;You can easily browse our ontology by looking at the profiles of a class and clicking through to parents and children. Here are profiles for some of the classes mentioned above:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.trueknowledge.com/p/book"&gt;[book]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.trueknowledge.com/p/written_publication"&gt;[written publication]&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.trueknowledge.com/p/comic"&gt;[comic]&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Instances of Classes&lt;/h2&gt;
&lt;p&gt;So far we've been talking about classes which are collections ordered in the ontology tree. So what about members of these classes? How does True Knowledge handle specific books like The Da Vinci Code?&lt;/p&gt;

&lt;p&gt;Each member of a class, for example each book, is an instance of that class. So &lt;a href="http://www.trueknowledge.com/p/%5Bthe_da_vinci_code%5D"&gt;[the da vinci code]&lt;/a&gt; is an instance of [book]. Likewise, &lt;a href="http://www.trueknowledge.com/p/dune"&gt;[dune]&lt;/a&gt; is also an instance of [book].&lt;/p&gt;

&lt;h2&gt;API Queries&lt;/h2&gt;

&lt;p&gt;To test these queries, you will need to use our &lt;a href="http://www.trueknowledge.com/api"&gt;API library&lt;/a&gt;. Details of our new API library are in &lt;a href="http://blog.trueknowledge.com/2009/08/new-php-api-library-and-example-code.html"&gt;this previous blog post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can get all subclasses of books that we know about with this query:&lt;/p&gt;
&lt;code&gt;
query bookclass&lt;br/&gt;
bookclass [is a subclass of] [book]&lt;/code&gt;

&lt;p&gt;The following TK Query gets a list of novels from True Knowledge:&lt;/p&gt;
&lt;code&gt;
query novel&lt;br/&gt;
novel [is an instance of] [novel]&lt;/code&gt;
&lt;p&gt;The query asks for a variable called &amp;quot;novel&amp;quot; which satisfies the relation &amp;quot;[is an instance of]&amp;quot; for the True Knowledge ID of the class [novel].&lt;/p&gt;

&lt;p&gt;Finally, you can tap into the power of having a structured ontology tree by getting a list of books, novels and everything else, with this query:&lt;/p&gt;

&lt;code&gt;
query book&lt;br/&gt;
book [is an instance of] [book]&lt;/code&gt;

&lt;p&gt;If you look through the list of results returned by the books query and compare it to the novels query results, you'll see overlap. This is because all instances of the class [novel] are also instances of the class [book] because [novel] is a subclass of [book]. You can go up the tree more and ask for all instances of the class [written publication], which will get you all books (including novels) and other publications.&lt;/p&gt;
</content:encoded>



<dc:creator>Pierre Far</dc:creator>
<pubDate>Thu, 10 Sep 2009 16:11:12 +0100</pubDate>

</item>
<item>
<title>A Question of Time: Answers that May Change</title>
<link>http://blog.trueknowledge.com/2009/09/a-question-of-time-answers-that-may-change.html</link>
<guid isPermaLink="true">http://blog.trueknowledge.com/2009/09/a-question-of-time-answers-that-may-change.html</guid>
<description>One of the key concepts with our semantic technology is answering questions whose answers vary depending on which time point the query refers to. Today, I'd like to explore the issues around such queries to help you get the most...</description>
<content:encoded>&lt;p&gt;One of the key concepts with our semantic technology is answering questions whose answers vary depending on which time point the query refers to. Today, I'd like to explore the issues around such queries to help you get the most out of our API when you use it.&lt;/p&gt;

&lt;h2&gt;Modeling Time&lt;/h2&gt;

&lt;p&gt;Broadly, our system supports four types of such queries, which we call temporal classes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Permanent, i.e. never changes. For example, &amp;quot;&lt;a href="http://www.trueknowledge.com/q/when_is_elvis_presley%27s_birthday"&gt;When is Elvis Presley's birthday?&lt;/a&gt;&amp;quot;.&lt;/li&gt;
&lt;li&gt;Transient, i.e. true for a period of time but not necessarily true before or after it. For example, holders of political office (&lt;a href="http://www.trueknowledge.com/q/who_is_the_prime_minister_of_the_uk"&gt;Who is the Prime Minister of the UK?&lt;/a&gt;) and other occupations, marital status (&lt;a href="http://www.trueknowledge.com/q/is_tom_cruise_married"&gt;Is Tom Cruise married?&lt;/a&gt;), country population, addresses (a company's HQ address for example) and more.&lt;/li&gt;
&lt;li&gt;Dynamic, i.e. changing very quickly. A good example is stock market data, exchange rates. These change too fast to have representations about periods of time and often require an external source.&lt;/li&gt;
&lt;li&gt;Unrevertable, i.e. Once the fact becomes true, it cannot change. Facts involving the attribute [dead] are an example. e.g. Compare &lt;a href="http://www.trueknowledge.com/q/is_elvis_presley_alive"&gt;Is Elvis Presley alive?&lt;/a&gt; and &lt;a href="http://www.trueknowledge.com/q/was_elvis_presley_alive_in_1970"&gt;Was Elvis Presley alive in 1970?&lt;/a&gt;. &lt;/li&gt;	
&lt;/ol&gt;

&lt;p&gt;True Knowledge models some facts as transient temporal facts even if they are so slow changing that people think of them as permanent. A good example is political geography where the borders can (and do) change in time, but at any given moment people think of them as permanent.&lt;/p&gt;

&lt;p&gt;There is one more temporal class, what we call "true now". For this class of facts, we simply represent that the knowledge is true at the moment the platform answers the query and don't represent historical information. This is commonly used as a convenience for lexical knowledge like facts which use the [can denote] relation. &lt;/p&gt;

&lt;h2&gt;Using our API&lt;/h2&gt;
&lt;p&gt;So now you know about how to think about time in relation to knowledge, let's look at some queries.&lt;/p&gt;

&lt;p&gt;You will need the &lt;a href="http://www.trueknowledge.com/api"&gt;True Knowledge API&lt;/a&gt; library which we talked about &lt;a href="http://blog.trueknowledge.com/2009/08/new-php-api-library-and-example-code.html"&gt;last time&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the Direct Answer API mode, you simply query in natural language. The examples above are a good start, and here is one more: &lt;a href="http://www.trueknowledge.com/q/who_was_prime_minister_of_the_uk_in_1969"&gt;Who was prime minister of the UK in 1969?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get you starting constructing True Knowledge Queries, as you would in an application, let's translate the above examples to TK Queries.&lt;/p&gt;

&lt;h3&gt;Poland and the EU&lt;/h3&gt;
&lt;p&gt;Let's look at these two queries:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;
query&lt;br/&gt;
f: [poland] [is a member of] [the european union]&lt;br/&gt;
f [applies at timepoint] [timepoint: ["2000"]]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;
query&lt;br/&gt;
f: [poland] [is a member of] [the european union]&lt;br/&gt;
f [applies at timepoint] [timepoint: ["2008"]]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We know that &lt;a href="http://www.trueknowledge.com/q/when_did_poland_join_the_eu"&gt;Poland joined the EU on 1st of May 2004&lt;/a&gt;, and so the queries above should, respectively, return a No and a Yes answer.&lt;/p&gt;

&lt;p&gt;These queries also introduce three new things to learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &amp;quot;f:&amp;quot; notation: This means &amp;quot;look up the fact ID&amp;quot; and you describe the fact after the colon. The f here is used to bind the variable f to the fact ID, and you can name the variable anything you want. Once bound, you can use the variable as usual in the query. This notation is the full notation for representing a fact including the id and the three entities, and the fact ID portion is optional. Missing it out, like all the queries from our previous post, still works.&lt;/li&gt;
&lt;li&gt;The [applies at timepoint] relation. We talked about relationships last time, and today we're using a new relation to specify when this fact applies.&lt;/li&gt;
&lt;li&gt;The notation for timepoints. It's the common notation of the format yyyy/mm/dd. For practice, try the two queries above with timepoints just before 1st of May 2004 (say 30th of April) and just after (2nd of May).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To generate the current timepoint (now) you can use a query line like the following: &lt;br /&gt;&lt;br /&gt;
&lt;code&gt;
[current time] [applies to] now&lt;br/&gt; &lt;br /&gt;
&lt;/code&gt;
This puts the time the query is executed into the variable now so to ask whether Poland is currently in the EU the query is:&lt;br /&gt;&lt;br /&gt;
&lt;code&gt;
query&lt;br /&gt;
[current time] [applies to] now&lt;br/&gt;
f: [poland] [is a member of] [the european union]&lt;br/&gt;
f [applies at timepoint] now&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;
&lt;/code&gt;

To ask "Who is the president of the US?", the query is:&lt;br /&gt;&lt;br /&gt;
&lt;code&gt;
query p&lt;br /&gt;
[current time] [applies to] now&lt;br /&gt;
f: p [is the president of] [the united states of america]&lt;br /&gt;
f [applies at timepoint] now&lt;br /&gt;
&lt;/p&gt;

&lt;h3&gt;Unrevertable Facts and Time Periods: Johnny Cash&lt;/h3&gt;
&lt;p&gt;This is similar to the queries above, but about unrevertable facts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;query&lt;br/&gt;
f: [alive] [applies to] [johnny cash]&lt;br/&gt;
f [applies at timepoint] [timepoint: ["2009"]]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;query&lt;br/&gt;
f: [alive] [applies to] [johnny cash]&lt;br/&gt;
f [applies at timepoint] [timepoint: ["2000"]]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Johnny Cash gives us another great example for time queries. To find out when he was alive, i.e. the time period between his birth day and his death, try this query:&lt;/p&gt;
&lt;code&gt;
query lifespan&lt;br/&gt;
f: [alive] [applies to] [johnny cash]&lt;br/&gt;
f [applies for timeperiod] lifespan&lt;/code&gt;
&lt;p&gt;Note another new relation, [applies for timeperiod], which is similar to the [applies at timepoint] relation we saw above.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;And so now you know how we work with time at True Knowledge and how to access time-based facts using our API. &lt;a href="http://trueknowledge.com/api"&gt;Download our API library&lt;/a&gt; and play with the queries above to see how it works. If you have any questions, please post in the comments below.&lt;/p&gt;




</content:encoded>



<dc:creator>Pierre Far</dc:creator>
<pubDate>Fri, 04 Sep 2009 16:56:48 +0100</pubDate>

</item>
<item>
<title>New PHP API Library and Example Code</title>
<link>http://blog.trueknowledge.com/2009/08/new-php-api-library-and-example-code.html</link>
<guid isPermaLink="true">http://blog.trueknowledge.com/2009/08/new-php-api-library-and-example-code.html</guid>
<description>The True Knowledge API is a very easy way for applications to tap into our semantic technology. To help developers start, we've had a PHP library that wraps up the mundane details of accessing our API. The library has served...</description>
<content:encoded>&lt;p&gt;The &lt;a href="http://www.trueknowledge.com/api/"&gt;True Knowledge API&lt;/a&gt; is a very easy way for applications to tap into our semantic technology.&lt;/p&gt;

&lt;p&gt;To help developers start, we've had a PHP library that wraps up the mundane details of accessing our API. The library has served us well and today we're announcing a beta version that is easier to use: The new library helps you send queries and get their results using simpler code. Also, the new library is easier to understand if you want to dig into the details of what's going on with each call.&lt;/p&gt;

&lt;h2&gt;Two APIs&lt;/h2&gt;
&lt;p&gt;Our API gives you two different modes of interaction:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Direct Answer (DA) mode where you query in natural language and get the answer(s) back. For example, you can ask "who was born on october 25?" and you will get a list of people that True Knowledge knows were born then.&lt;/li&gt;
&lt;li&gt;The True Knowledge Query (TK Query) mode where you use our internal query language to get the answers you want.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For equivalent searches, the DA is slower because it has to process your natural language query and translate it into a TK Query but it's simpler to use and reflects how users actually search.&lt;/p&gt;

&lt;h2&gt;Getting Started&lt;/h2&gt;
&lt;p&gt;It's easy to get started:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.trueknowledge.com/api/signup/"&gt;Register for an API account&lt;/a&gt;, which is different from your True Knowledge account (if you have one).&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.trueknowledge.com/api/download/lib/"&gt;Download the new beta version of the PHP library&lt;/a&gt; and look at the included examples.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Example Code &amp;amp; Sandbox&lt;/h2&gt;
&lt;p&gt;Included in the PHP library download is an examples directory with two files called da.php and tkquery.php that you can use to build on.&lt;/p&gt;
&lt;p&gt;You need to specify your API account ID and password (the equivalent of an API key) near the top of the example files. It's a pair of define() statements.&lt;/p&gt;
&lt;p&gt;If you want a lower-level look at our API, the &lt;a href="http://www.trueknowledge.com/api/"&gt;API home page&lt;/a&gt; also has a sandbox for you to test our queries and see the raw query URLs and XML being returned.&lt;/p&gt;

&lt;h2&gt;DA Query Examples&lt;/h2&gt;
&lt;p&gt;DA queries are very easy: your query is how you would phrase it in English. Some examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Where can I buy a pillow in Glasgow? This gives you results like our &lt;a href="http://local.trueknowledge.com/"&gt;local product search engine&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;List US states. This returns a list of the US states.&lt;/li&gt;
&lt;li&gt;Is the Eiffel Tower older than the Statue of Liberty? This demonstrates the inference (deduction) ability of True Knowledge's semantic technology, and it gives you a direct simple answer: No.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;True Knowledge Query Examples&lt;/h2&gt;
&lt;p&gt;True Knowledge Queries (TK Queries) are written in the internal query language. Think of it as SQL for knowledge.&lt;/p&gt;
&lt;p&gt;When I was learning TK Queries, I understood them best when I realized they're a bit like logic and algebra. A query starts by saying "I want to know about something" and then goes on to describe how to derive the answer in a logical manner.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;code&gt;
query x&lt;br&gt;
x [is an instance of] [james bond movie]
&lt;/code&gt;
&lt;p&gt;The first line says "I want to know about something I'm calling x". You can call your variable anything you want; a more apt name here is 'movie' because of the second line. Just like other programming languages, it's good to pick sensible variable names!&lt;/p&gt;
&lt;p&gt;The second line describes what x is: it is an instance of a class of objects labeled "james bond movie". Because True Knowledge stores knowledge in a structured and hierarchical manner, all James Bond movies are a type of one class, and so we're asking for every member of that class.&lt;/p&gt;
&lt;p&gt;Notice the use of "[is an instance of]". This is what we call a relation and it is one type of relationship we know about. A relationship links two bits of knowledge together. In our example, we're linking the variable 'x' to the class [james bond movie].&lt;/p&gt;

&lt;p&gt;True Knowledge understands many relations, and the trick is to find one that will solve your query. Over the next few weeks, we'll be writing more about how to do TK Queries and diving into their details and doing more complex examples.&lt;/p&gt;

&lt;p&gt;Another example:&lt;/p&gt;
&lt;code&gt;
query place, place_info&lt;br&gt;
["chicago"] [can denote] place /r&lt;br&gt;
place [is an instance of] [geographical area]&lt;br&gt;
place [uniquely translates as] place_info&lt;/code&gt;
&lt;p&gt;This query breaks down as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We're asking True Knowledge for two variables: something we're calling 'place' and another we're calling 'place_info'.&lt;/li&gt;
&lt;li&gt;This thing called 'place' we are interested can be referred to as "Chicago". The /r tells the TK Query to ignore rare and less common translations of the query. So in this case, we're really interested in the famous Chicago, not any other town also called Chicago. For fun, try your queries both with and without the /r.&lt;/li&gt;
&lt;li&gt;In the third line, we explain more about 'place' saying it belongs to a class of things we call 'geographical area's. The second and third lines together uniquely identify the well known city in Illinois.&lt;/li&gt;
&lt;li&gt;Finally we ask for a unique (long) "noun phrases" that describes the 'place' we just found. True Knowledge stores a phrase (called a URS) for each object we have in our database, and so asking for it gives you more content to add to your query results explaining to the user what True Knowledge just returned.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Feedback and Getting More Help&lt;/h2&gt;
&lt;p&gt;As this is a beta version of the API library, we would love your feedback in how it's working (or not) for you. We are actively developing this library as a replacement for the old one, and so your feedback will directly influence this development!&lt;/p&gt;

&lt;p&gt;The easiest way to give us feedback is to use the &lt;a href="http://support.trueknowledge.com/forums/21661/entries"&gt;API support forums&lt;/a&gt;, which True Knowledge employees constantly read.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://support.trueknowledge.com/forums/21661/entries"&gt;forums&lt;/a&gt; are also the best place to get help directly from us and other API users.&lt;/p&gt;

&lt;p&gt;To access the forums, you will need to sign in with your True Knowledge account (&lt;a href="http://www.trueknowledge.com/register/"&gt;register here&lt;/a&gt;), which is different from your API account.&lt;/p&gt;

&lt;p&gt;Don't forget to subscribe to this blog too to stay updated with API news and examples in the future!&lt;/p&gt;</content:encoded>



<dc:creator>Pierre Far</dc:creator>
<pubDate>Tue, 25 Aug 2009 16:47:42 +0100</pubDate>

</item>

</channel>
</rss><!-- ph=1 --><!-- nhm:dynamic-ssi -->
