<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Soroush Saffari on Medium]]></title>
        <description><![CDATA[Stories by Soroush Saffari on Medium]]></description>
        <link>https://medium.com/@sorsaffari?source=rss-80ec376615c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pUJr2ZPdTyHCdcutyLa_Ug@2x.jpeg</url>
            <title>Stories by Soroush Saffari on Medium</title>
            <link>https://medium.com/@sorsaffari?source=rss-80ec376615c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:37:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sorsaffari/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[New Grakn Documentation]]></title>
            <link>https://medium.com/vaticle/new-grakn-documentation-bcac37f37a53?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcac37f37a53</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[grakn]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[graql]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Fri, 04 Jan 2019 12:38:03 GMT</pubDate>
            <atom:updated>2022-03-29T16:48:29.722Z</atom:updated>
            <content:encoded><![CDATA[<h3>Announcing Our New Grakn Documentation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MbJKchqdBPh13-GG839KUQ.png" /></figure><p>After carefully listening to your and the community’s feedback, we’ve decided to make some drastic improvements to our documentation platform. I’m very excited to share this with you!</p><p>A technology as essential as Grakn needs to be thoroughly documented. That means that you, or any new Grakn developer, must be taken on a journey where you can learn about all the capabilities and use cases involved in building a Grakn knowledge graph. So with this in mind, we set out to rethink our existing documentation, and we ended up rewriting all of the content while restructuring the architecture to make it more centred around the developer experience.</p><p>You’ll see that the new documentation takes a use-case centric approach while providing full coverage of what you can get out of working with Grakn and Graql. This new style aims to incorporate the seamless flow that was so loved in the previous Grakn Academy while widening the coverage of the entire documentation.</p><p>The new content architecture, at <a href="http://dev.grakn.ai/">dev.grakn.ai</a>, now splits the documentation into two parts: Grakn and Graql. Each part contains multiple chapters, such as <a href="https://dev.grakn.ai/docs/running-grakn/install-and-run">Running Grakn</a>, <a href="https://dev.grakn.ai/docs/client-api/overview">Client API</a>, and<a href="https://dev.grakn.ai/docs/cloud-deployment/kgms"> Cloud Deployment</a> for Grakn, and <a href="https://dev.grakn.ai/docs/schema/overview">Schema</a>, <a href="https://dev.grakn.ai/docs/query/overview">Query</a> and <a href="https://dev.grakn.ai/docs/concept-api/overview">Concept API</a> for Graql. Each chapter contains several pages, which will grow and evolve over time while remaining encapsulated within their chapter. The new structure, which is reflected in the navigation sidebar, maps directly to the Grakn architecture and is easily extendible as each chapter evolves independently along with its associated Grakn module.</p><p>I hope you find the new <a href="http://www.vaticle.com/">Grakn Documentation</a> useful. It’s still really at the beginning of its roadmap, as it will grow with some exciting content. This includes the modelling philosophy, the content and use cases, the usability and functionality of the site as well as maintaining the content for the past releases; There is still room for improvement in each of these areas.</p><p><em>And, as always, I welcome your feedback and contributions to help us grow our </em><a href="https://github.com/graknlabs/docs"><em>Grakn Docs</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcac37f37a53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/new-grakn-documentation-bcac37f37a53">New Grakn Documentation</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protein Structure & Function Prediction Powered by a Grakn Knowledge Graph]]></title>
            <link>https://medium.com/vaticle/protein-structure-function-prediction-powered-by-a-grakn-knowledge-graph-fea667483e78?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fea667483e78</guid>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[protein]]></category>
            <category><![CDATA[biology]]></category>
            <category><![CDATA[biotechnology]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Sat, 03 Nov 2018 16:23:30 GMT</pubDate>
            <atom:updated>2022-03-29T16:53:22.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CbJyAMDRHjgzErDiG0MN8A.png" /></figure><p>Ever since we’ve been able to sequence proteins, three-dimensional structures have received a tremendous experimental attention. Thanks to the development of new methods and technological advancements, determining these structures has become a more accurate and progressive process over time.</p><p>The problem, however, lays in the fact that the progress of discovering new protein structures has not kept pace with the rate at which new sequences are being produced. As a result, we see a continuously growing gap between the number of new sequences being produced and the three-dimensional structures being identified.</p><p>Given sufficient accuracy, a possible solution is the computational prediction of protein structures. Methods such as homology modelling, fold recognition and novel modelling can be used to fill in this gap. However, regardless of which method is used, with the rapid rise in the amount of sequence data, the underlying problem remains to be the lack of one single knowledge base that allows a rapid and powerful scan over the universe of protein sequences. All publicly available data currently sits in various databases across many different sources. Moving from one source to another is not — and certainly must not — be the biggest challenge in this process.</p><p>In this post, I aim to show how a Knowledge Graph can accelerate the protein structure prediction process by allowing you to:</p><ul><li><strong>query for insights</strong> over one single, comprehensive and interconnected dataset of protein sequences, and</li><li>to search and produce a <strong>shortlisted set of sequences</strong> to be passed on to the next computational component in the prediction process.</li></ul><h3>All Data In One Knowledge Graph</h3><p>The image below illustrates how I think the model of a knowledge graph in this domain of protein sequence structure could look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zq6-2rbFhcaPUqL0k3z1Pw.png" /><figcaption>The model of this Grakn knowledge graph: the red node is an entity, green nodes are relationships and blue nodes are attributes.</figcaption></figure><p>This Grakn knowledge graph plays the role of a single knowledge base that contains all relevant data pulled in from various sources, such as Uniprot and PDB. The data could also be pulled in from running <a href="https://blog.grakn.ai/using-a-grakn-knowledge-graph-for-biological-sequence-alignment-analysis-592fa962d5e4"><strong>BLAST with Grakn</strong></a>.</p><blockquote>Migrating data to Grakn: To learn how data in CSV, JSON and XML formats can be migrated to a Grakn Knowledge Graph, have a look at the comprehensive and step-by-step <a href="http://dev.grakn.ai/docs/examples/phone-calls-overview#whats-covered">Migration Guide</a>.</blockquote><h3>Query For Insights</h3><p>Now that we have all relevant data represented (as shown above) in a Grakn knowledge graph, we can go ahead and ask the following questions over this dataset. Under each question, I’ve included the relevant query.</p><ul><li>What are the structures of the following sequence?</li></ul><pre>MNVGTAHSEVNPNTRVMNSRGIWLSYVLAIGLLHIVLLSIPFVSVPVVWTLTNLIHNMGMYIFLHTVKGTPFETPDQGKARLLTHWEQMDYGVQFTASRKFLTITPIVLYFLTSFYTKYDQIHFVLNTVSLMSVLIPKLPQLHGVRIFGINKY</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b290aee0ef4a883a8577ed7b29b6e07/href">https://medium.com/media/0b290aee0ef4a883a8577ed7b29b6e07/href</a></iframe><ul><li>Which sequences have the structure with PDB id of &quot;2RHC&quot;?</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eac0a4f8e14e54bb8fcf2003cc96ba2f/href">https://medium.com/media/eac0a4f8e14e54bb8fcf2003cc96ba2f/href</a></iframe><ul><li>The following sequence has no known structure. What are the structures of other sequences that are at least 80% identical to this particular sequence?</li></ul><pre>MNVGTAHSEVNPNTRVMNSRGIWLSYVLAIGLLHIVLLSIPFVSVPVVWTLTNL IHNMGMYIFLHTVKGTPFETPDQGKARLLTHWEQMDYGVQFTASRKFLTITPIVLYFLTSFYTKYDQIHFVLNTVSLMSVLIPKLPQLHGVRIFGINKY</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd49331456f4be01d014e5fc86ce4338/href">https://medium.com/media/cd49331456f4be01d014e5fc86ce4338/href</a></iframe><p>The code you saw above is Graql. Graql is the language for <a href="http://www.vaticle.com/">Grakn</a>. Its expressivity is what makes it extremely human-readable and intuitive. In simple terms, Graql is a query language that can be understood and written by anyone, not just programmers.</p><h3>Extending the Knowledge Graph</h3><p>As we decide to pull in more relevant data sources into the Grakn knowledge graph, the model can evolve and be extended with minimal effort.</p><h4>An Example</h4><p>Below I’ve included the code that defines the model that I illustrated earlier in this post. If we were to extend this model and introduce the protein sequence function with a mapping relationship to protein sequence structure, we could do so by extending the model (aka. schema) like so:</p><pre>define<br>  sequence-sequence-alignment sub relationship,<br>    relates target-sequence,<br>    relates matched-sequence,<br>    has identicality,<br>    has positivity;</pre><pre>sequence-structure-mapping sub relationship,<br>    relates mapped-structure,<br>    relates mapping-sequence;</pre><pre><strong>structure-function-mapping sub relationship,<br>    relates mapping-structure,<br>    relates mapped-function;</strong></pre><pre>sequence sub attribute datatype string,<br>    plays target-sequence,<br>    plays matched-sequence,<br>    plays mapping-sequence;</pre><pre>structure sub entity,<br>    plays mapped-structure,<br><strong>    plays mapping-structure,<br></strong>    has pdb-id;</pre><pre><strong>function sub attribute datatype string,<br>    plays mapped-function;</strong></pre><pre>identicality sub attribute datatype double;<br>  positivity sub attribute datatype double;<br>  pdb-id sub attribute datatype string;</pre><p>The bolded lines above is the extra code that we need to add. Nothing else needs to change. This extended model of the knowledge graph looks like this now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2nLG_9G0rWBBIkgye79mg.png" /><figcaption>The extended model: ‘function’ is added as an attribute and mapped with ‘structure’ (directly) and with ‘sequence’ (via inference)</figcaption></figure><p>Given the new relationship structure-function-mapping and the previous relationship sequence-structure-mapping, we can make use of Grakn’s <strong>automated reasoning</strong> capability to make an inference, resulting in new knowledge — the implied sequence-function-mapping relationship.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af513ce2524b85e0b5a1fa2855411c13/href">https://medium.com/media/af513ce2524b85e0b5a1fa2855411c13/href</a></iframe><p>The implied-sequence-function-mapping rule above is telling Grakn that:</p><h4>when:</h4><ul><li>there is a sequence, and</li><li>there is a structure, and</li><li>there is a function, and</li><li>the sequence and the structure have a mapping relationship, and</li><li>the structure and the function have a mapping relationship,</li></ul><h4>then:</h4><ul><li>consider the sequence and the function to have a mapping relationship.</li></ul><p>With these additions to the schema, we can now ask the following questions:</p><ul><li>Which sequences have the function “enzyme”?</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a3ebb4944348bfb8141ecda2849ab1f/href">https://medium.com/media/4a3ebb4944348bfb8141ecda2849ab1f/href</a></iframe><ul><li>Which functions are mapped either directly to the following sequence or indirectly via an aligned sequence that is at least 80% identical to the given sequence?</li></ul><pre>The sequence: MNVGTAHSEVNPNTRVMNSRGIWLSYVLAIGLLHIVLLSIPFVSVPVVWTLTNL IHNMGMYIFLHTVKGTPFETPDQGKARLLTHWEQMDYGVQFTASRKFLTITPIVLYFLTSFYTKYDQIHFVLNTVSLMSVLIPKLPQLHGVRIFGINKY</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90200391e45b048daa193ad548861a94/href">https://medium.com/media/90200391e45b048daa193ad548861a94/href</a></iframe><h3>Grakn Rules</h3><p>What you saw above is simply one example of how a Grakn knowledge graph can be extended to infer new knowledge. Rules can be written in any research domain to:</p><ul><li>inject biological facts</li><li>infer based on new findings (hypotheses)</li><li>enforce constraints</li></ul><p>It’s entirely up to you how you choose to make your knowledge graph more intelligent by writing rules tailored to your own work.</p><h3>The Opportunities are endless!</h3><p>Grakn is about modelling intelligent knowledge graphs in an intelligent way. We believe simplicity to be a cornerstone of intelligence. Hence, the query language — Graql. What you can model and query with a Grakn knowledge graph is only limited by your will and imagination.</p><p><a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">See an example</a> of the thought process behind modelling a dataset in Grakn. Read about the Schema <a href="http://dev.grakn.ai/docs/schema/concepts">Concepts</a> and <a href="http://dev.grakn.ai/docs/schema/rules">Rules</a>. Go through <a href="http://dev.grakn.ai/docs/examples/phone-calls-queries">examples of Graql queries</a> or see how to <a href="http://dev.grakn.ai/docs/query/overview">write your own</a>.</p><h3>For Your Inspiration</h3><ul><li><a href="https://blog.grakn.ai/using-a-grakn-knowledge-graph-for-biological-sequence-alignment-analysis-592fa962d5e4">Sequence Alignment Analysis</a></li><li><a href="https://blog.grakn.ai/biograkn-accelerating-biomedical-knowledge-discovery-with-a-grakn-knowledge-graph-84706768d7d4">Accelerating Biomedical Knowledge Discovery</a></li><li><a href="https://blog.grakn.ai/drug-repositioning-with-a-grakn-ai-knowledge-graph-for-bioinformatics-4701591f38c1">Drug Repositioning</a></li></ul><h3>Have an idea?</h3><p>I’d love to hear about how you see Grakn applicable in your field. Whether it’s a question, comment or feedback, get in touch with me on <a href="https://discord.com/invite/vaticle">Grakn’s slack community</a>, shoot me an email at soroush@grakn.ai or tweet me at <a href="https://twitter.com/SaffariSoroush">@SaffariSoroush</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fea667483e78" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/protein-structure-function-prediction-powered-by-a-grakn-knowledge-graph-fea667483e78">Protein Structure &amp; Function Prediction Powered by a Grakn Knowledge Graph</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loading data into a Grakn Knowledge Graph using the Java client]]></title>
            <link>https://medium.com/vaticle/loading-data-into-a-grakn-knowledge-graph-using-the-java-client-5f2f1a7f9903?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f2f1a7f9903</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Wed, 31 Oct 2018 20:28:09 GMT</pubDate>
            <atom:updated>2022-03-29T16:55:21.401Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuol99m9eVRcZRyBKWPn7A.png" /></figure><h4>This tutorial may be out of date against the latest version of Grakn. For the most up-to-date version of this tutorial, please refer to the <a href="http://dev.grakn.ai/docs/examples/phone-calls-migration-java">Grakn Documentation</a>.</h4><p>This tutorial illustrates how a dataset in CSV, JSON or XML format can be migrated into a <a href="http://www.vaticle.com/">Grakn</a> knowledge graph, using <a href="https://github.com/graknlabs/grakn/tree/master/client-java"><strong>Grakn’s Java Client</strong></a><strong>.</strong></p><p>The knowledge graph that we’ll work on in this post, is called phone_calls. The schema for this knowledge graph was defined in a previous post, <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">here</a>.</p><p>If you’re already familiar with Grakn, and all you need is a migration example to follow, you’ll find <a href="https://github.com/graknlabs/examples/tree/master/java/migration">this Github repository</a> useful. If, on the other hand, you’re not familiar with the technology, make sure to first complete <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">defining the schema</a> for the phone_calls knowledge graph, and read on for a detailed guide on migrating data into Grakn using Java.</p><h3>A Quick Look into the phone_calls Schema</h3><p>Before we get started with migration, let’s have a quick reminder of how the schema for the phone_calls knowledge graph looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wi2AWdMWfqgJ4fAVF1a_uw.png" /><figcaption>The visualised schema for the phone_calls knowledge graph: blue nodes are attributes, red nodes are entities and the green nodes are relationships</figcaption></figure><h3>Migrate Data into Grakn</h3><p>Let’s go through an overview of how the migration takes place.</p><ol><li>First, we need need to talk to our Grakn keyspace. To do this, we’ll use the Grakn’s <a href="http://dev.grakn.ai/docs/examples/phone-calls-queries">Java Client</a>.</li><li>We’ll go through each data file, extracting each data item and parsing it to a JSON object.</li><li>We’ll pass each data item (in the form of a JSON object) to its corresponding template. What the template returns is a Graql query for inserting that item into Grakn.</li><li>We’ll execute each of those queries to load the data into our target keyspace — phone_calls.</li></ol><p>Before moving on, make sure you have <strong>Java 1.8 </strong>installed and the <a href="http://dev.grakn.ai/docs/running-grakn/install-and-run#start-the-grakn-server"><strong>Grakn server</strong></a><strong> </strong>running on your machine.</p><h3>Getting Started</h3><h4>Create a new Maven project</h4><p>This project uses SDK 1.8 and is named phone_calls. I’ll be using IntelliJ as the IDE.</p><h4>Set Grakn as a dependency</h4><p>Modify pom.xml to include the latest version of Grakn (1.4.2) as a dependency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d1e400c7b3bfdcb008ab606787ce2b9/href">https://medium.com/media/1d1e400c7b3bfdcb008ab606787ce2b9/href</a></iframe><h4>Configure logging</h4><p>We’d like to be able to configure what Grakn logs out. To do this, modify pom.xml to exclude slf4j shipped with grakn and add logback as a dependency, instead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac10c29fbcf56273df1df5a26e3a40ce/href">https://medium.com/media/ac10c29fbcf56273df1df5a26e3a40ce/href</a></iframe><p>Next, add a new file called logback.xml with the content below and place it under src/main/resources.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2e9bfa5712d9b6f695e90a983c65ce6/href">https://medium.com/media/d2e9bfa5712d9b6f695e90a983c65ce6/href</a></iframe><h4>Create the Migration Class</h4><p>Under src/main create a new file called Migration.java. This is where we’re going to write all our code.</p><h3>Including the Data Files</h3><p>Pick one of the data formats below and download the files. After you download each of the four files, place them under the src/main/resources/data directory. We’ll be using these to load their data into our phone_calls knowledge graph.</p><p><strong>CSV: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/companies.csv">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/people.csv">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/contracts.csv">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/calls.csv">calls</a></p><p><strong>JSON: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/companies.json">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/people.json">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/contracts.json">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/calls.json">calls</a></p><p><strong>XML: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/companies.xml">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/people.xml">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/contracts.xml">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/calls.xml">calls</a></p><p>All code that follows is to be written in Migration.java<em>.</em></p><h3>Specifying details for each data file</h3><p>Before anything, we need a structure to contain the details required for reading data files and constructing Graql queries. These details include:</p><ul><li>The path to the data file, and</li><li>The template function that receives a JSON object and produces a Graql insert query.</li></ul><p>For this purpose, we create a new subclass called Input.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7cccd54471f52c3e919066dc34a59b8/href">https://medium.com/media/f7cccd54471f52c3e919066dc34a59b8/href</a></iframe><p>Later in this article, we’ll see how an instance of the Input class can be created, but before we get to that, let’s add the mjson dependency to the dependencies tag in our pom.xml file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74468820ca10f243516e37e57ae41ac1/href">https://medium.com/media/74468820ca10f243516e37e57ae41ac1/href</a></iframe><p>Time to initialise the inputs.</p><p>The code below calls the initialiseInputs() method which returns a collection of inputs. We’ll then use each input element in this collection to load each data file into Grakn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b9b6ccc90460a27a3022f0d3c0ffc3d/href">https://medium.com/media/7b9b6ccc90460a27a3022f0d3c0ffc3d/href</a></iframe><h4>Input instance for a Company</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f646a25320ad8a8b24f119ed0e7c5c9/href">https://medium.com/media/7f646a25320ad8a8b24f119ed0e7c5c9/href</a></iframe><p>input.getDataPath() will return data/companies.</p><p>Given company is</p><pre>{ name: &quot;Telecom&quot; }</pre><p>input.template(company) will return</p><pre>insert $company isa company has name &quot;Telecom&quot;;</pre><h4>Input instance for a Person</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d357456fee80428437add6466b4a554/href">https://medium.com/media/8d357456fee80428437add6466b4a554/href</a></iframe><p>input.getDataPath() will return data/people.</p><p>Given person is</p><pre>{ phone_number: &quot;+44 091 xxx&quot; }</pre><p>input.template(person) will return</p><pre>insert $person has phone-number &quot;+44 091 xxx&quot;;</pre><p>And given person is</p><pre>{ firs-name: &quot;Jackie&quot;, last-name: &quot;Joe&quot;, city: &quot;Jimo&quot;, age: 77, phone_number: &quot;+00 091 xxx&quot;}</pre><p>input.template(person) will return</p><pre>insert $person has phone-number &quot;+44 091 xxx&quot; has first-name &quot;Jackie&quot; has last-name &quot;Joe&quot; has city &quot;Jimo&quot; has age 77;</pre><h4>Input instance for a Contract</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/754d6b0c2b6cbf90d7687dfa08b4f1e7/href">https://medium.com/media/754d6b0c2b6cbf90d7687dfa08b4f1e7/href</a></iframe><p>input.getDataPath() will return data/contracts.</p><p>Given contract is</p><pre>{ company_name: &quot;Telecom&quot;, person_id: &quot;+00 091 xxx&quot; }</pre><p>input.template(contract) will return</p><pre>match $company isa company has name &quot;Telecom&quot;; $customer isa person has phone-number &quot;+00 091 xxx&quot;; insert (provider: $company, customer: $customer) isa contract;</pre><h4>Input instance for a Call</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba3354edea76fe84fe2bd8582635d493/href">https://medium.com/media/ba3354edea76fe84fe2bd8582635d493/href</a></iframe><p>input.getDataPath() will return data/calls.</p><p>Given call is</p><pre>{ caller_id: &quot;+44 091 xxx&quot;, callee_id: &quot;+00 091 xxx&quot;, started_at: 2018–08–10T07:57:51, duration: 148 }</pre><p>input.template(call) will return</p><pre>match $caller isa person has phone-number &quot;+44 091 xxx&quot;; $callee isa person has phone-number &quot;+00 091 xxx&quot;; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018–08–10T07:57:51; $call has duration 148;</pre><h3>Connect and Migrate</h3><p>Now that we have the datapath and template defined for each of our data files, we can continue to connect with our phone_calls knowledge graph and load the data into it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5790c3fac00094da01532ea9087f39c/href">https://medium.com/media/f5790c3fac00094da01532ea9087f39c/href</a></iframe><p>connectAndMigrate(Collection&lt;Input&gt; inputs) is the only method that will be fired to initiate migration of the data into the phone_calls knowledge graph.</p><p>The following happens in this method:</p><ol><li>A Grakn instance grakn is created, connected to the server we have running locally at localhost:48555.</li><li>A session is created, connected to the keyspace phone_calls.</li><li>For each input object in the inputs collection, we call the loadDataIntoGrakn(input, session). This will take care of loading the data as specified in the input object into our keyspace.</li><li>Finally the session is closed.</li></ol><h3>Loading the data into phone_calls</h3><p>Now that we have a session connected to the phone_calls keyspace, we can move on to actually loading the data into our knowledge graph.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cb4af11e78a716fba7cca98be0a086a/href">https://medium.com/media/3cb4af11e78a716fba7cca98be0a086a/href</a></iframe><p>In order to load data from each file into Grakn, we need to:</p><ol><li>retrieve an ArrayList of JSON objects, each of which represents a data item. We do this by calling parseDataToJson(input), and</li><li>for each JSON object in items: a) create a transaction tx, b) construct the graqlInsertQuery using the corresponding template, c) run the query, d)commit the transaction and e) close the transaction.</li></ol><blockquote><strong>Note on creating and committing transactions: </strong>To avoid running out of memory, it’s recommended that every single query gets created and committed in a single transaction. However, for faster migration of large datasets, this can happen once for every <em>n</em> queries, where <em>n</em> is the maximum number of queries guaranteed to run on a single transaction.</blockquote><p>Now that we’ve done all the above, we’re ready to read each file and parse each data item to a JSON object. It’s these JSON objects that will be passed to the template method on each Input object.</p><p>We‘re going to write the implementation of parseDataToJson(input).</p><h3>DataFormat-specific implementation</h3><p>The implementation for parseDataToJson(input) differs based on what format our data files have.</p><p>.csv, .json or .xml.</p><p>But regardless of what the data format is, we need the right setup to read the files line by line. For this, we’ll use an InputStreamReader.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dc2b867393f19487e6c31f2d1f29c3a/href">https://medium.com/media/6dc2b867393f19487e6c31f2d1f29c3a/href</a></iframe><h4>Parsing CSV</h4><p>We’ll use the <a href="https://www.univocity.com/pages/univocity_parsers_documentation">Univocity CSV Parser</a> for parsing our .csv files. Let’s add the dependency for it. We need to add the following to the dependencies tag in pom.xml.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea3d13c3928a242ee249d7af1e21d5b4/href">https://medium.com/media/ea3d13c3928a242ee249d7af1e21d5b4/href</a></iframe><p>Having done that, we’ll write the implementation of parseDataToJson(input) for parsing .csv files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5dc96a5108e571e57b25023e380cd727/href">https://medium.com/media/5dc96a5108e571e57b25023e380cd727/href</a></iframe><p>Besides this implementation, we need to make one more change.</p><p>Given the nature of CSV files, the JSON object produced will have all the columns of the .csv file as its keys, even when the value is not there, it’ll be taken as a null.</p><p>For this reason, we need to change one line in the template method for the input instance for <em>person</em>.</p><p>if (! person.has(&quot;first_name&quot;)) {...}</p><p>becomes</p><p>if (person.at(“first_name”).isNull()) {...}.</p><h4>Reading JSON</h4><p>We’ll use <a href="https://google.github.io/gson/apidocs/com/google/gson/stream/JsonReader.html">Gson’s JsonReader</a> for reading our .json files. Let’s add the dependency for it. We need to add the following to the dependencies tag in pom.xml.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f6e53a754909f1ee4c0bfc8b3eabfe0/href">https://medium.com/media/6f6e53a754909f1ee4c0bfc8b3eabfe0/href</a></iframe><p>Having done that, we’ll write the implementation of parseDataToJson(input) for reading .json files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c298845c473fac3883f5caa596f8570/href">https://medium.com/media/7c298845c473fac3883f5caa596f8570/href</a></iframe><h4>Parsing XML</h4><p>We’ll use Java’s built-in <a href="https://docs.oracle.com/cd/E13222_01/wls/docs90/xml/stax.html">StAX</a> for parsing our .xml files.</p><p>For parsing XML data, we need to know the name of the target tag. This needs to be declared in the Input class and specified when constructing each input object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c39d52c5f039da5ca3b4248e8de2abf2/href">https://medium.com/media/c39d52c5f039da5ca3b4248e8de2abf2/href</a></iframe><p>And now for the implementation of parseDataToJson(input) for parsing .xml files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6d64de8ac536c04be82188144556417/href">https://medium.com/media/f6d64de8ac536c04be82188144556417/href</a></iframe><h3>Putting it all together</h3><p>Here is how our Migrate.java looks like for loading CSV data into Grakn, and find here the ones for <a href="https://gist.github.com/sorsaffari/6e26c6c3ce5f12788e017f3cd67bf038">JSON</a> and <a href="https://gist.github.com/sorsaffari/2f91334ea2cab7fa92602d24f3ce845e">XML</a> files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cbf81ddedb7d73d7429f7939b52f7fa/href">https://medium.com/media/3cbf81ddedb7d73d7429f7939b52f7fa/href</a></iframe><h3>Time to Load</h3><p>Run the main method, sit back, relax and watch the logs while the data starts pouring into Grakn.</p><h3>To Recap</h3><ul><li>We started off by setting up our project and positioning the data files.</li><li>Next, we went on to set up the migration mechanism, one that was independent of the data format.</li><li>Then, we learned how files with different data formats can be parsed into JSON objects.</li><li>Lastly, we ran the main method which fired the connectAndMigrate method with the given inputs. This loaded the data into our <a href="http://www.vaticle.com/">Grakn</a> knowledge graph.</li></ul><h3>Next</h3><p>In the next post (to be published soon), we’ll see how we can get insights over this dataset by querying the phone_calls knowledge graph using the Graql console, Grakn Workbase and the Java client. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f2f1a7f9903" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/loading-data-into-a-grakn-knowledge-graph-using-the-java-client-5f2f1a7f9903">Loading data into a Grakn Knowledge Graph using the Java client</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using a Grakn Knowledge Graph for Biological Sequence Alignment Analysis]]></title>
            <link>https://medium.com/vaticle/using-a-grakn-knowledge-graph-for-biological-sequence-alignment-analysis-592fa962d5e4?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/592fa962d5e4</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[biology]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[protein]]></category>
            <category><![CDATA[dna]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Tue, 16 Oct 2018 08:46:46 GMT</pubDate>
            <atom:updated>2022-03-29T17:00:22.536Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using a Grakn Knowledge Graph for Sequence Alignment Analysis</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_f1d1EY6z9yJF3K_d87ZQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLtEF8_xCPklaTR4RaB3ng9V3Ov7n980cQ&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPZoG-M_hY30&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPZoG-M_hY30%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ca19e89cb379dd9a52ddc2a1af6b610/href">https://medium.com/media/1ca19e89cb379dd9a52ddc2a1af6b610/href</a></iframe><p>The sequencing of proteins and DNA has arguably become one of the biggest biological evolutions in the last 50 years. It has enabled researchers to produce sequence alignments that can be precisely analysed for discovering meaningful and evolutionary relationships.</p><p><a href="https://blast.ncbi.nlm.nih.gov/Blast.cgi">The Basic Local Alignment Tool</a> (BLAST) has become the go-to place for many bioinformaticians who routinely search for sequence alignments, as part of their research workflow. The flexibility of its search algorithms and the reliable output produced by them are known to be the main reasons for BLAST’s ever-growing popularity.</p><p>There are many articles that delve deep into explaining the capabilities and performance of various BLAST algorithms. In this post, however, we aim to focus on the <em>workflow</em> that involves using BLAST. This article attempts to show how this workflow can be significantly improved to:</p><ul><li>reduce the time the researcher spends on pre-processing the data, and</li><li>to represent and visualise the BLAST output in a more efficient way that enables more in-depth and interconnected analysis.</li></ul><h3>The Typical Workflow</h3><p>The diagram below illustrates the typical workflow of using BLAST in a research environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aVZPMHAimzYN4qN66U6Epw.jpeg" /><figcaption>The typical BLAST workflow</figcaption></figure><p>As we can see here, for each target sequence, the researcher has to:</p><ol><li>run a BLAST search,</li><li>go through the BLAST Report to identify the relevant alignments,</li><li>transfer each identified alignment to one single spreadsheet, and</li><li>use that as a base for analysis.</li></ol><p>Imagine repeating the above for 1000 target sequences. If there is one word that could describe the insanity of this process, it would be “tedious”. I doubt that any bioinformatician sees their skills and intelligence utilised in a process that is heavily slowed down by such an enormous overhead.</p><p>Furthermore, the flat representation of data in a spreadsheet or the BLAST report as seen below, or any table-based view for that matter, is in no way the best approach to represent such complex and interconnected data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQq_gWaXYQMGuGRnETaJUg.png" /><figcaption>A typical BLAST report</figcaption></figure><p>It’s clear that this workflow is far from ideal. An optimised alternative would be one that:</p><ol><li>automates the manual process of running BLAST searches, and</li><li>automatically pulls the output of each BLAST search into one single knowledge graph that represents the data in its true nature — complex and interconnected.</li></ol><h3>An Optimised Workflow</h3><p>The diagram below illustrates a workflow that requires minimal effort to pre-process and prepare multiple BLAST outputs for analysis and discovery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWMH4g_V_TPU6goh58gkeg.jpeg" /><figcaption>An optimised workflow</figcaption></figure><p>As shown in the diagram above, <a href="http://www.vaticle.com/">Grakn</a>’s Knowledge Graph plays the role of a central (single) knowledge base that contains the results from all BLAST searches. Here is how the process takes places:</p><ol><li>A set of proteins are imported into the knowledge graph.</li><li>A Graql query is written to extract the target sequences from the knowledge graph.</li><li>A BLAST search runs for each of the target sequences, via the <a href="https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&amp;PAGE_TYPE=BlastDocs&amp;DOC_TYPE=DeveloperInfo">NCBI BLAST API</a>.</li><li>As soon as each BLAST search completes, the alignments and all their interconnected data are imported back into the knowledge graph.</li><li>The analysis begins by querying the knowledge graph to filter and provide the relevant alignments found by multiple BLAST searches.</li></ol><p>By now you might have already guessed it — a workflow that relies heavily on such automation can only be feasible by writing code. That couldn’t be further from the truth, but at the end of the day it’s about how much effort we have to put into it, and if the outcome is worth it.</p><p>To answer this question, we built an example knowledge graph for protein sequences, and set up the automated components around it.</p><p>More <strong>technical details</strong> about this example as well as full instructions about running it on your machine, are available on the <a href="https://github.com/graknlabs/biograkn/tree/master/examples/blast">github.com &gt; graknlabs &gt; biograkn &gt; blast</a> repository.</p><h4>The Ontology of Protein Sequence Alignments</h4><p>Before we can see some example queries, it’s important that we understand how the knowledge graph is modelled — a representation that truly describes a proteins dataset for sequence alignments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*856RqLV118JdVeVidb0ixA.png" /><figcaption>red nodes are entities, green nodes are relationships and blue nodes are attributes</figcaption></figure><p>The visualised model above translates to:</p><ul><li><strong>A protein</strong>: a) has a name, a sequence and an identifier, b) is owned by a species, c) is stored in a database</li><li><strong>The sequence of a protein</strong>: a) can have an alignment with another protein sequence, b) is stored in a database</li><li><strong>An alignment between two sequences</strong>: a) implies an alignment between the proteins<strong> </strong>that own the aligned sequences b) has identicality, positivity, gaps, midline and an identifier (the BLAST Reference)</li><li><strong>A Species</strong>: has name</li><li><strong>A Database</strong>: has name</li></ul><h3>Analysing Alignments in a Knowledge Graph</h3><p>What follows is a small set of query examples that are merely meant for demonstration purposes of Graql — Grakn’s query language.</p><h4>Filter Based on the Alignment’s Attributes</h4><p>Below is the sequence for the target protein <em>ORM1-like protein 3.</em></p><pre>MNVGTAHSEVNPNTRVMNSRGIWLSYVLAIGLLHIVLLSIPFVSVPVVWTLTNLIHNMGMYIFLHTVKGTPFETPDQGKARLLTHWEQMDYGVQFTASRKFLTITPIVLYFLTSFYTKYDQIHFVLNTVSLMSVLIPKLPQLHGVRIFGINKY</pre><p>We’d like to get sequence alignments with <em>identicality of at least</em> 90% and <em>positivity of at least</em> <em>85%</em>.</p><p><strong>Query and Visualise</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e6cd4df4e0748b36e9bd8d87c3f36c8/href">https://medium.com/media/3e6cd4df4e0748b36e9bd8d87c3f36c8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FukerkkTR8rx07T6wGGRVw.png" /><figcaption>Purple nodes are proteins (target at top | matched at bottom), green nodes are protein sequences, blue nodes are attributes of the alignment and red node is the database that contains the matched protein</figcaption></figure><p><strong>Query and Get Results</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aa9eaff43b0024871dfb9397dd74d37/href">https://medium.com/media/9aa9eaff43b0024871dfb9397dd74d37/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/657314637520ce54ec5f89c915ea2f5c/href">https://medium.com/media/657314637520ce54ec5f89c915ea2f5c/href</a></iframe><h4>Filter based on the Species of Matched Sequences</h4><p>Given the same protein sequence as shown above, we’d like to get only the sequence alignments, where the matched sequence belongs to the species <em>Fukomys damarensis.</em></p><p><strong>Query and Visualise</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba950272eca5fcc7f34aa24286763464/href">https://medium.com/media/ba950272eca5fcc7f34aa24286763464/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6feUkFMCO50MB3BWukg9A.png" /><figcaption>Purple nodes are proteins (target at top | matched at bottom), green nodes are protein sequences, blue nodes are attributes of the alignment and red node is the species that has the matched protein</figcaption></figure><p><strong>Query and Get Results</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a375c210551018c9f206a48a94649f1/href">https://medium.com/media/4a375c210551018c9f206a48a94649f1/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c19f495b12dfa96b7144f4f8587bac1c/href">https://medium.com/media/c19f495b12dfa96b7144f4f8587bac1c/href</a></iframe><h4>Filter Based on a Particular Subset of the Matched Sequences</h4><p>Given the same protein sequence as above, we’d like to get only the sequence alignments that contain the subset <em>KF.</em></p><p><strong>Query and Visualise</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12e05d5ae703555600133ca9dce7729e/href">https://medium.com/media/12e05d5ae703555600133ca9dce7729e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FUi9sD4L-bPw8OYQdsCC_w.png" /><figcaption>Purple nodes are proteins (target at top | matched at bottom), green nodes are the protein sequences and blue nodes are attributes of the alignments</figcaption></figure><p><strong>Query and Get Results</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec27cb14adda9e14ce52af276960b662/href">https://medium.com/media/ec27cb14adda9e14ce52af276960b662/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/946c61980e145d9e545ca525ba9b0307/href">https://medium.com/media/946c61980e145d9e545ca525ba9b0307/href</a></iframe><h3>The Code</h3><p>The code you saw above is Graql. <a href="http://www.vaticle.com/">Graql is the language for Grakn</a> — the knowledge graph. The expressivity of Graql is what makes it the most readable query language since the beginning of databases. In simple terms, Graql is a language that can be understood and written by anyone, not just programmers.</p><p>In this optimised workflow, Graql is used for analysis. The part of the code that automates the workflow consists of two files:</p><ol><li>migrate.py: reads a .fasta file containing 12 proteins that relate to <em>asthma</em> (exported from <a href="https://uniprot.org/">UniProt</a>) and inserts each protein along with its sequence into the knowledge graph.</li><li>blast.py: 1) extracts the target sequences from the knowledge graph, 2) runs a BLAST search for each sequence, and 3) imports the result from each BLAST search back into the knowledge graph.</li></ol><p>To run this example on your local machine, follow these <a href="https://github.com/graknlabs/biograkn/tree/master/examples/blast">instructions</a>.</p><h3>Tip of the Iceberg</h3><p>This example only touches the surface of how a knowledge graph can revolutionise workflows that rely on bioinformatic analytical tools, such as BLAST. The schema presented in this article can be extended and others can be modelled to represent complex <a href="http://dev.grakn.ai/docs/schema/concepts">concepts</a> and <a href="http://dev.grakn.ai/docs/schema/rules">rules</a>. This enables writing powerful and intuitive <a href="http://dev.grakn.ai/docs/query/overview">Graql queries</a> for obtaining valuable insights over complex datasets.</p><p>Grakn’s Knowledge Graph has the potential to complement a vast majority of Biological Research domains. Some of those fields include; analysing DNA sequence alignments, exploring genomics, drug discovery, disease networks, neuro-informatics, and even investigating protein structure, function, properties and classifications.</p><h3>We want to hear from you :)</h3><p>Share your unique experience in using BLAST and how you think this optimised workflow relates (or not) to the way you use BLAST. As a part of this or other workflows, what other publicly available analytical tools and programs do you normally use? How do you see a central knowledge base in form of a knowledge graph, adding value in your field?</p><p><a href="https://grakn.ai/slack">Talk to us</a> and <a href="https://discuss.grakn.ai/">discuss</a> your ideas with the Grakn community 🙂</p><p>If you have any questions or comments about this work, please send me an email at soroush@grakn.ai or tweet me <a href="https://twitter.com/SaffariSoroush">@SaffariSoroush</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=592fa962d5e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/using-a-grakn-knowledge-graph-for-biological-sequence-alignment-analysis-592fa962d5e4">Using a Grakn Knowledge Graph for Biological Sequence Alignment Analysis</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loading data and querying knowledge from a Grakn Knowledge Graph using the Python client]]></title>
            <link>https://medium.com/vaticle/loading-data-and-querying-knowledge-from-a-grakn-knowledge-graph-using-the-python-client-b764a476cda8?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b764a476cda8</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 10:23:26 GMT</pubDate>
            <atom:updated>2022-03-29T17:04:13.080Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBbeXge7sPsVpubrQ2LCKA.png" /></figure><h4>This tutorial may be out of date against the latest version of Grakn. For the most up-to-date version of this tutorial, please refer to the <a href="http://dev.grakn.ai/docs/examples/phone-calls-migration-python">Grakn Documentation</a>.</h4><p>This tutorial illustrates, using the <a href="http://dev.grakn.ai/docs/client-api/python"><strong>Grakn Python Client</strong></a>:</p><ul><li>First: how to <strong>migrate a dataset in CSV, JSON or XML format into a Grakn</strong> knowledge graph.</li><li>Next: how to <strong>query our newly created knowledge graph</strong> to gain interesting insights over an example dataset.</li></ul><p>The knowledge graph that we will work on in this post, is called phone_calls. The schema for this knowledge graph was defined in a previous post, <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">here</a>.</p><h3>For the experienced engineer</h3><p>If all you need is a good example that shows how migrating data into <a href="http://www.vaticle.com/">Grakn</a> works, you’ll find what you’re looking for <a href="https://github.com/graknlabs/examples/tree/master/python/migration">here</a>.</p><h3>The Step by Step Guide</h3><p>If you’d like to follow this tutorial step by step, it’s important that you understand what we are working on here. This tutorial assumes that you have completed <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">defining the schema</a> for phone_calls; the knowledge graph we’ll be working on, in this post.</p><h3>A Quick Look into the phone_calls Schema</h3><p>Before we get started with migration, let’s have a quick reminder of how the schema for the phone_calls knowledge graph looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GliKHDwiqo-W8L3Q274u9A.png" /></figure><h3>First: Migrate Data into Grakn</h3><p>Let’s go through an overview of how the migration takes place.</p><ol><li>we need a way to talk to our Grakn keyspace. To do this, we will use the Grakn’s <a href="http://dev.grakn.ai/docs/client-api/python">Python Client</a>.</li><li>we will go through each data file, extracting each data item and parsing it to a Python dictionary.</li><li>we will pass each data item (in the form of a Python dictionary) to its corresponding template function, which in turn gives us the constructed Graql query for inserting that item into Grakn.</li><li>we will execute each of those queries to load the data into our target keyspace — phone_calls.</li></ol><p>Before moving on, make sure you have <strong>Python3 </strong>and<strong> Pip3</strong> installed and the <a href="http://dev.grakn.ai/docs/running-grakn/install-and-run#start-the-grakn-server"><strong>Grakn server</strong></a><strong> </strong>running on your machine.</p><h3>Getting Started</h3><ol><li>Create a directory named phone_calls<em> </em>on your desktop.</li><li>cd to the phone_calls directory via terminal.</li><li>Run pip3 install grakn to install the <a href="http://dev.grakn.ai/docs/client-api/python">Grakn Python Client</a>.</li><li>Open the phone_calls<em> </em>directory in your favourite text editor.</li><li>Create a migrate.py file in the root directory. This is where we’re going to write all our code.</li></ol><h3>Including the Data Files</h3><p>Pick one of the data formats below and download the files. After you download them, place the four files under the phone_calls/data directory. We will be using these to load their data into our phone_calls knowledge graph.</p><p><strong>CSV: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/companies.csv">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/people.csv">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/contracts.csv">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/csv/data/calls.csv">calls</a></p><p><strong>JSON: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/companies.json">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/people.json">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/contracts.json">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/json/data/calls.json">calls</a></p><p><strong>XML: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/companies.xml">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/people.xml">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/contracts.xml">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/python/migration/xml/data/calls.xml">calls</a></p><h3>Setting up the migration mechanism</h3><p>All code that follows is to be written in phone_calls/migrate.py<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cafb72a705fce9614b7fb03b0b94075/href">https://medium.com/media/9cafb72a705fce9614b7fb03b0b94075/href</a></iframe><p>First thing first, we import the grakn module. We will use it for connecting to our phone_calls<em> </em>keyspace.</p><p>Next, we declare the inputs<strong>.</strong> More on this later. For now, what we need to understand about inputs — it’s a list of dictionaries, each one containing:</p><ul><li>The path to the data file</li><li>The template function that receives a dictionary and produces the Graql insert query. We will define these template functions in a bit.</li></ul><p>Let’s move on.</p><h4>build_phone_call_graph(inputs)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c0bed4103822e92768ee514ed740ee0/href">https://medium.com/media/3c0bed4103822e92768ee514ed740ee0/href</a></iframe><p>This is the main and only function we need to call to start loading data into Grakn.</p><p>What happens in this function, is as follows:</p><ol><li>A Grakn client is created, connected to the server we have running locally.</li><li>A session is created, connected to the keyspace phone_calls. Note that by using with, we indicate that the session will close after it’s been used.</li><li>For each input dictionary in inputs, we call the load_data_into_grakn(input, session). This will take care of loading the data as specified in the input dictionary into our keyspace.</li></ol><h4>load_data_into_grakn(input, session)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a331bf8d817bc737fbf27957d134296/href">https://medium.com/media/1a331bf8d817bc737fbf27957d134296/href</a></iframe><p>In order to load data from each file into Grakn, we need to:</p><ol><li>retrieve a list containing dictionaries, each of which represents a data item. We do this by calling parse_data_to_dictionaries(input)</li><li>for each dictionary in items: a) create a transaction tx, which closes once used, b) construct the graql_insert_query using the corresponding template function, c) run the query and d)commit the transaction.</li></ol><blockquote><strong>Note on creating and committing transactions: </strong>To avoid running out of memory, it’s recommended that every single query gets created and committed in a single transaction. However, for faster migration of large datasets, this can happen once for every <em>n</em> queries, where <em>n</em> is the maximum number of queries guaranteed to run on a single transaction.</blockquote><p>Before we move on to parsing the data into dictionaries, let’s start with the template functions.</p><h3>The Template Functions</h3><p>Templates are simple functions that accept a dictionary, representing a single data item. The values within this dictionary fill in the blanks of the query template. The result will be a Graql insert query.</p><p>We need 4 of them. Let’s go through them one by one.</p><h4>company_template</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bfab2da99b1b0f50305369495195c50/href">https://medium.com/media/1bfab2da99b1b0f50305369495195c50/href</a></iframe><p>Example:</p><ul><li>Goes in: { name: &quot;Telecom&quot; }</li><li>Comes out: insert $company isa company has name &quot;Telecom&quot;;</li></ul><h4>person_template</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b974c75bd4d61bc407c33d49aae35681/href">https://medium.com/media/b974c75bd4d61bc407c33d49aae35681/href</a></iframe><p>Example:</p><ul><li>Goes in: { phone_number: &quot;+44 091 xxx&quot; }</li><li>Comes out: insert $person has phone-number &quot;+44 091 xxx&quot;;</li></ul><p>or:</p><ul><li>Goes in: { firs-name: &quot;Jackie&quot;, last-name: &quot;Joe&quot;, city: &quot;Jimo&quot;, age: 77, phone_number: &quot;+00 091 xxx&quot;}</li><li>Comes out: insert $person has phone-number &quot;+44 091 xxx&quot; has first-name &quot;Jackie&quot; has last-name &quot;Joe&quot; has city &quot;Jimo&quot; has age 77;</li></ul><h4>contract_template</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94a10dc45099c1848ea1a425eed9ea47/href">https://medium.com/media/94a10dc45099c1848ea1a425eed9ea47/href</a></iframe><p>Example:</p><ul><li>Goes in: { company_name: &quot;Telecom&quot;, person_id: &quot;+00 091 xxx&quot; }</li><li>Comes out: match $company isa company has name &quot;Telecom&quot;; $customer isa person has phone-number &quot;+00 091 xxx&quot;; insert (provider: $company, customer: $customer) isa contract;</li></ul><h4>call_template</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7998d75cceea3eb586b6ed8ea4de879f/href">https://medium.com/media/7998d75cceea3eb586b6ed8ea4de879f/href</a></iframe><p>Example:</p><ul><li>Goes in: { caller_id: &quot;+44 091 xxx&quot;, callee_id: &quot;+00 091 xxx&quot;, started_at: 2018–08–10T07:57:51, duration: 148 }</li><li>Comes out: match $caller isa person has phone-number &quot;+44 091 xxx&quot;; $callee isa person has phone-number &quot;+00 091 xxx&quot;; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018–08–10T07:57:51; $call has duration 148;</li></ul><p>We’ve now created a template for each and all four concepts that were <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">previously</a> defined in the schema.</p><p>It’s time for the implementation of parse_data_to_dictionaries(input).</p><h3>DataFormat-specific implementation</h3><p>The implementation for parse_data_to_dictionaries(input) differs based on what format our data files have.</p><p>.csv, .json or .xml.</p><h4>Parsing CSV</h4><p>We will use Python’s built-in <a href="https://docs.python.org/3/library/csv.html#dialects-and-formatting-parameters">csv library</a>. Let’s import the module for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8765d9fef8dba491de7c12d16332466c/href">https://medium.com/media/8765d9fef8dba491de7c12d16332466c/href</a></iframe><p>Moving on, we will write the implementation of parse_data_to_dictionaries(input) for parsing .csv files. Note that we use <a href="https://docs.python.org/3/library/csv.html#csv.DictReader">DictReader</a> to map the information in each row to a dictionary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceabd796ce1bac2fce949bba2451777c/href">https://medium.com/media/ceabd796ce1bac2fce949bba2451777c/href</a></iframe><p>Besides this function, we need to make one more change.</p><p>Given the nature of CSV files, the dictionary produced will have all the columns of the .csv file as its keys, even when the value is not there, it’ll be taken as a blank string.</p><p>For this reason, we need to change one line in our person_template function.</p><p>if &quot;first_name&quot; in person becomes if person[&quot;first_name&quot;] == &quot;&quot;.</p><h4>Parsing JSON</h4><p>We will use <a href="https://pypi.org/project/ijson/">ijson</a>, an iterative JSON parser with a standard Python iterator interface.</p><p>Via the terminal, while in the phone_calls directory, run pip3 install ijson and import the module for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/868252c2aa6c8b86dd6c8b1edadd5b76/href">https://medium.com/media/868252c2aa6c8b86dd6c8b1edadd5b76/href</a></iframe><p>Moving on, we will write the implementation of parse_data_to_dictionaries(input) for processing.json files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2491fa2d33e531061891c2a51bf87e8/href">https://medium.com/media/f2491fa2d33e531061891c2a51bf87e8/href</a></iframe><h4>Parsing XML</h4><p>We will use Python’s built-in <a href="https://docs.python.org/2/library/xml.etree.elementtree.html">xml.etree.cElementTree library</a>. Let’s import the module for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6529a7c5f0cc599773de355f308f6371/href">https://medium.com/media/6529a7c5f0cc599773de355f308f6371/href</a></iframe><p>For parsing XML data, we need to know the target tag name. This needs to be specified for each data file in our inputs deceleration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/159cb1f0b7f9ff1f7fa81374401accb9/href">https://medium.com/media/159cb1f0b7f9ff1f7fa81374401accb9/href</a></iframe><p>And now for the implementation of parse_data_to_dictionaries(input) for parsing .xml files.</p><p>The implementation below, although, not the most generic, performs well with very large .xml files. Note that many libraries that do xml to dictionary parsing, pull in the entire .xml file into memory first. There is nothing wrong with that approach when you’re dealing with small files, but when it comes to large files, that’s just a no go.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a44e2d077059efa673e3b2d742b9b0d3/href">https://medium.com/media/a44e2d077059efa673e3b2d742b9b0d3/href</a></iframe><h3>Putting it all together</h3><p>Here is how our migrate.py looks like for loading CSV data into Grakn, and find here are the ones for <a href="https://gist.github.com/sorsaffari/edd1e19bd958d86e1dc3b0c779247880">JSON</a> and <a href="https://gist.github.com/sorsaffari/097ff583ab9d074b62a30945251087d4">XML</a> files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/793431d11c327cc1ca082605034eb93c/href">https://medium.com/media/793431d11c327cc1ca082605034eb93c/href</a></iframe><h3>Time to Load</h3><p>Run python3 migrate.py</p><p>Sit back, relax and watch the logs while the data starts pouring into Grakn.</p><h4>… so far with the migration</h4><p>We started off by setting up our project and positioning the data files.</p><p>Next we went on to set up the migration mechanism, one that was independent of the data format.</p><p>Then, we went ahead and wrote the template functions whose only job was to construct a Graql insert query based on the data passed to them.</p><p>After that, we learned how files with different data formats can be parsed into Python dictionaries.</p><p>Lastly, we ran python3 migrate.py which fired the build_phone_call_graph<em> </em>function with the given inputs. This loaded the data into our Grakn knowledge graph.</p><h3>Next: Query the Knowledge Graph</h3><p>When we <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">modelled and loaded the schema into Grakn</a>, we had some insights in mind that we wanted to obtain from phone_calls; the knowledge graph.</p><p>Let’s revise:</p><ul><li>Since September 14th, which customers called person X?</li><li>Who are the people who have received a call from a London customer aged over 50 who has previously called someone aged under 20?</li><li>Who are the common contacts of customers X and Y?</li><li>Who are the customers who 1) have all called each other and 2) have all called person X at least once?</li><li>How does the average call duration among customers aged under 20 compare those aged over 40?</li></ul><p>For the rest of this post, we will go through each of these questions to:</p><ul><li>understand their business value,</li><li>write them as a statement,</li><li>write them in <a href="http://dev.grakn.ai/docs/query/overview">Graql</a>, and</li><li>assess their result.</li></ul><p>Make sure you have the <a href="http://dev.grakn.ai/docs/workbase/overview">Workbase</a> opened, while phone_calls selected as the keyspace (in the top-right hand corner).</p><p>Let’s begin.</p><h3>Since September 14th, which customers called person X?</h3><h4>The business value:</h4><pre>The person with phone number +86 921 547 9004 has been identified as a lead. We (company &quot;Telecom&quot;) would like to know which of our customers have been in contact with this person since September 14th. This will help us in converting this lead into a customer.</pre><h4>As a statement:</h4><pre>Get me the customers of company “Telecom” who called the target person with phone number +86 921 547 9004 from September 14th onwards.</pre><h4>In Graql:</h4><pre>match<br>  $customer isa person has phone-number $phone-number;<br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $customer, provider: $company) isa contract;<br>  $target isa person has phone-number &quot;+86 921 547 9004&quot;;<br>  (caller: $customer, callee: $target) isa call has started-at<br>  $started-at;<br>  $min-date == 2018-09-14T17:18:49; $started-at &gt; $min-date;<br>get $phone-number;</pre><h4>The result:</h4><pre>[ &#39;+62 107 530 7500&#39;, &#39;+370 351 224 5176&#39;, &#39;+54 398 559 0423&#39;, <br>  &#39;+7 690 597 4443&#39;,  &#39;+263 498 495 0617&#39;, &#39;+63 815 962 6097&#39;, <br>  &#39;+81 308 988 7153&#39;, &#39;+81 746 154 2598&#39;]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-BZNFArBfGfnRQ4_QrSYg.png" /><figcaption>Using Workbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IXifx70chmHSQq3GNyHyQ.png" /><figcaption><strong>USING THE GRAQL CONSOLE</strong></figcaption></figure><blockquote><a href="/service/ttp://dev.grakn.ai/docs/get-started/graql-console"><strong>The Graql Console</strong></a> is used to execute Graql queries from the command line, or to let Graql be invoked from other applications.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17a5fe8e5ab527c66f101e587717390a/href">https://medium.com/media/17a5fe8e5ab527c66f101e587717390a/href</a></iframe><h3>Who are the people who have received a call from a London customer aged over 50 who has previously called someone aged under 20?</h3><h4>The business value:</h4><pre>We (company &quot;Telecom&quot;) have received a number of harassment reports, which we suspect is caused by one individual. The only thing we know about the harasser is that he/she is aged roughly over 50 and lives in London. The reports have been made by young adults all aged under 20. We wonder if there is a pattern and so would like to speak to anyone who has received a call from a suspect, since he/she potentially started harassing.</pre><h4>As a statement:</h4><pre>Get me the phone number of people who have received a call from a customer aged over 50 after this customer (suspect) made a call to another customer aged under 20.</pre><h4>In Graql:</h4><pre>match<br>  $suspect isa person has city &quot;London&quot;, has age &gt; 50;<br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $suspect, provider: $company) isa contract;<br>  $pattern-callee isa person has age &lt; 20;<br>  (caller: $suspect, callee: $pattern-callee) isa call <br>    has started at $pattern-call-date;<br>  $target isa person has phone-number $phone-number, <br>    has is-customer false;<br>  (caller: $suspect, callee: $target) isa call <br>    has started-at $target-call-date;<br>  $target-call-date &gt; $pattern-call-date;<br>get $phone-number;</pre><h4>The result:</h4><pre>[ &#39;+30 419 575 7546&#39;,  &#39;+86 892 682 0628&#39;, &#39;+1 254 875 4647&#39;, <br>  &#39;+351 272 414 6570&#39;, &#39;+33 614 339 0298&#39;, &#39;+86 922 760 0418&#39;, <br>  &#39;+86 825 153 5518&#39;,  &#39;+48 894 777 5173&#39;, &#39;+351 515 605 7915&#39;, <br>  &#39;+63 808 497 1769&#39;,  &#39;+27 117 258 4149&#39;, &#39;+86 202 257 8619&#39; ]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZzDuw6W6-BuHADXFi-Hug.png" /><figcaption>Using Workbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*awsYHq91nrJcacWo-IuEPg.png" /><figcaption><strong>USING THE GRAQL CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccdd29e8ae173a56c37baeb3c4135013/href">https://medium.com/media/ccdd29e8ae173a56c37baeb3c4135013/href</a></iframe><h3>Who are the common contacts of customers X and Y?</h3><h4>The business value:</h4><pre>The customer with phone number +7 171 898 0853 and +370 351 224 5176 have been identified as friends. We (company &quot;Telecom&quot;) like to know who their common contacts are in order to offer them a group promotion.</pre><h4>As a statement:</h4><pre>Get me the phone number of people who have received calls from both customer with phone number +7 171 898 0853 and customer with phone number +370 351 224 5176.</pre><h4>In Graql:</h4><pre>match<br>  $common-contact isa person has phone-number $phone-number;<br>  $customer-a isa person has phone-number &quot;+7 171 898 0853&quot;;<br>  $customer-b isa person has phone-number &quot;+370 351 224 5176&quot;;<br>  (caller: $customer-a, callee: $common-contact) isa call;<br>  (caller: $customer-b, callee: $common-contact) isa call;<br>get $phone-number;</pre><h4>The result:</h4><pre>[&#39;+86 892 682 0628&#39;, &#39;+54 398 559 0423&#39;]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mKLY5G1PEWFDe3KvRr0wzA.png" /><figcaption>Using Workbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sr6QtApU0GPqd-tdngcFA.png" /><figcaption><strong>USING THE GRAQL CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55e173438b66918e32a06eeaa15640d5/href">https://medium.com/media/55e173438b66918e32a06eeaa15640d5/href</a></iframe><h3>Who are the customers who 1) have all called each other and 2) have all called person X at least once?</h3><h4>The business value:</h4><pre>The person with phone number +48 894 777 5173 has been identified as a lead. We (company &quot;Telecom&quot;) would like to know who his circle of  (customer) contacts are, so that we can encourage them in converting this lead to a customer.</pre><h4>As a statement:</h4><pre>Get me the phone phone number of all customers who have called each other as well the person with phone number +48 894 777 5173.</pre><h4>In Graql:</h4><pre>match<br>  $target isa person has phone-number &quot;+48 894 777 5173&quot;;<br>  $company isa company has name &quot;Telecom&quot;;<br>  $customer-a isa person has phone-number $phone-number-a;<br>  $customer-b isa person has phone-number $phone-number-b;<br>  (customer: $customer-a, provider: $company) isa contract;<br>  (customer: $customer-b, provider: $company) isa contract;<br>  (caller: $customer-a, callee: $customer-b) isa call;<br>  (caller: $customer-a, callee: $target) isa call;<br>  (caller: $customer-b, callee: $target) isa call;<br>get $phone-number-a, $phone-number-b;</pre><h4>The result:</h4><pre>[ &#39;+62 107 530 7500&#39;, &#39;+261 860 539 4754&#39;, &#39;+81 308 988 7153&#39; ]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqJv07bl577lw9XWwEDd5A.png" /><figcaption><strong>USING THE GRAQ CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e1b7049fd2625c45d992e577fcc863d/href">https://medium.com/media/6e1b7049fd2625c45d992e577fcc863d/href</a></iframe><h3>How does the average call duration among customers aged under 20 compare with those aged over 40?</h3><h4>The business value:</h4><pre>In order to better understand our customers&#39; behaviour, we (company &quot;Telecom&quot;) like to know how the average phone call duration among those aged under 20 compares to those aged over 40.</pre><p>Two queries need to be executed to provide this insight.</p><h4>Query 1: aged under 20</h4><h4>As a statement:</h4><pre>Get me the average call duration among customers who have a contract with company &quot;Telecom&quot; and are aged under 20.</pre><h4>In Graql:</h4><pre>match <br>  $customer isa person has age &lt; 20; <br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $customer, provider: $company) isa contract;<br>  (caller: $customer, callee: $anyone) isa call has duration<br>  $duration; <br>aggregate mean $duration;</pre><h4>The result:</h4><pre>1348 seconds</pre><h4>Query 2: aged over 40</h4><h4>As a statement:</h4><pre>Get me the average call duration among customers who have a contract with company &quot;Telecom&quot; and are aged over 40.</pre><h4>In Graql:</h4><pre>match <br>  $customer isa person has age &gt; 40; <br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $customer, provider: $company) isa contract;<br>  (caller: $customer, callee: $anyone) isa call has duration<br>  $duration; <br>  aggregate mean $duration;</pre><h4>The result:</h4><pre>1587 seconds</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSjWMetuILbHT7vWVBjGxQ.png" /><figcaption><strong>USING THE GRAQL SHELL</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eec4b85f21d642f438f4626dd9f92f88/href">https://medium.com/media/eec4b85f21d642f438f4626dd9f92f88/href</a></iframe><h3>👏 You’ve done it!</h3><p>Five Graql queries, each written in a few lines, answered all of our questions. Our imaginary client, Telecom, can now take these insights back to their team and, hopefully, use them responsibly to serve their customers. You are the one who made it happen!</p><h3>🚀 There is (always) more!</h3><p>This, by no means, should be the end of our phone_calls Grakn knowledge graph. Try the <a href="https://github.com/graknlabs/examples/tree/master/python/queries">interactive query executor</a> , play around with it and write your own <a href="http://dev.grakn.ai/docs/query/overview">Graql queries</a> to gain more interesting insights over this dataset.</p><p>Model the <a href="http://dev.grakn.ai/docs/schema/overview">schema</a> for your own brand new knowledge graph! Head to the <a href="http://dev.grakn.ai/docs">Grakn Documentation</a> and learn more about the cool things you can do with Grakn.</p><p><a href="https://grakn.ai/slack">Talk to us</a>, <a href="https://discuss.grakn.ai/">discuss</a> your ideas and <a href="https://github.com/graknlabs/grakn">contribute</a> to <a href="http://www.vaticle.com/">Grakn</a>!</p><p>Stay tuned for more Grakn <a href="https://github.com/graknlabs/examples">examples</a> 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b764a476cda8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/loading-data-and-querying-knowledge-from-a-grakn-knowledge-graph-using-the-python-client-b764a476cda8">Loading data and querying knowledge from a Grakn Knowledge Graph using the Python client</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who’s calling? Grakn Node.js client. Migrate (csv, json and xml) & query the knowledge graph]]></title>
            <link>https://medium.com/vaticle/whos-calling-grakn-node-js-client-migrate-csv-json-and-xml-query-the-knowledge-graph-d8261e5d210b?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8261e5d210b</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Fri, 28 Sep 2018 14:45:49 GMT</pubDate>
            <atom:updated>2022-03-29T17:05:58.859Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4dVDAjSVfIed7JPJs1lqdg.png" /></figure><h4>This tutorial may be out of date against the latest version of Grakn. For the most up-to-date version of this tutorial, please refer to the <a href="http://dev.grakn.ai/docs/examples/phone-calls-migration-nodejs">Grakn Documentation</a>.</h4><p>This tutorial illustrates, using the <a href="http://dev.grakn.ai/docs/client-api/nodejs"><strong>Grakn Node.js Client</strong></a>:</p><ul><li>First: how to <strong>migrate a dataset in CSV, JSON or XML format into a </strong><a href="http://www.vaticle.com/"><strong>Grakn</strong></a> knowledge graph.</li><li>Next: how to <strong>query our newly created knowledge graph</strong> to gain interesting insights over an example dataset.</li></ul><p>The knowledge graph that we will work on in this post, is called phone_calls, The schema for this knowledge graph was defined in a previous post, <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">here</a>.</p><h3>For the experienced engineer</h3><p>If all you need is a good example that shows how migrating data into Grakn works, you’ll find what you’re looking for <a href="https://github.com/graknlabs/examples/tree/master/nodejs/migration">here</a>.</p><h3>The Step by Step Guide</h3><p>If you’d like to follow this tutorial step by step, it’s important that you understand what we are working on here. This tutorial assumes that you have completed <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">defining the schema</a> for phone_calls; the knowledge graph we’ll be working on, in this post.</p><h3>A Quick Look into the phone_calls Schema</h3><p>Before we get started with migration, let’s have a quick reminder of how the schema for the phone_calls knowledge graph looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GliKHDwiqo-W8L3Q274u9A.png" /></figure><h3>First: Migrate Data into Grakn</h3><p>Let’s go through an overview of how the migration takes place.</p><ol><li>we need a way to talk to our Grakn keyspace. To do this, we will use the <a href="http://dev.grakn.ai/docs/client-api/nodejs">Node.js Client</a>.</li><li>we will go through each data file, extracting each data item and parsing it to a Javascript object.</li><li>we will pass each data item (in the form of a Javascript object) to its corresponding template function, which in turn gives us the constructed Graql query for inserting that item into Grakn.</li><li>we will execute each of those queries to load the data into our target keyspace — phone_calls.</li></ol><p>Before moving on, make sure you have <strong>npm </strong>installed and the <a href="http://dev.grakn.ai/docs/running-grakn/install-and-run#start-the-grakn-server"><strong>Grakn server </strong></a>running on your machine.</p><h3>Getting Started</h3><ol><li>Create a directory named phone_calls<em> </em>on your desktop.</li><li>cd to the phone_calls directory via terminal.</li><li>Run npm install grakn to install the <a href="http://dev.grakn.ai/docs/client-api/nodejs">Node.js Client</a>.</li><li>Open the phone_calls<em> </em>directory in your favourite text editor.</li><li>Create a migrate.js file in the root directory. This is where we’re going to write all our code.</li></ol><h3>Including the Data Files</h3><p>Pick one of the data formats below and download the files. After you download them, place the four files under the phone_calls/data directory. We will be using these to load their data into our phone_calls knowledge graph.</p><p><strong>CSV: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/csv/data/companies.csv">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/csv/data/people.csv">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/csv/data/contracts.csv">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/csv/data/calls.csv">calls</a></p><p><strong>JSON: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/json/data/companies.json">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/json/data/people.json">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/json/data/contracts.json">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/json/data/calls.json">calls</a></p><p><strong>XML: </strong><a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/xml/data/companies.xml">companies</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/xml/data/people.xml">people</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/xml/data/contracts.xml">contracts</a> | <a href="https://raw.githubusercontent.com/graknlabs/examples/master/nodejs/migration/xml/data/calls.xml">calls</a></p><h3>Setting up the migration mechanism</h3><p>All code that follows is to be written in phone_calls/migrate.js<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e32ad9f7ab3ea7fe517e6c38f2e3178/href">https://medium.com/media/3e32ad9f7ab3ea7fe517e6c38f2e3178/href</a></iframe><p>First thing first, we require the grakn module. We will use it for connecting to our phone_calls<em> </em>keyspace.</p><p>Next, we declare the inputs<strong>.</strong> More on this later. For now, what we need to understand about inputs — it’s an array of objects, each one containing:</p><ul><li>The path to the data file</li><li>The template function that receives an object and produces the Graql insert query. We will define these template functions in a bit.</li></ul><p>Let’s move on.</p><h4>buildPhoneCallGraph(inputs)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cbbf417277f378af053c87512e659b1/href">https://medium.com/media/8cbbf417277f378af053c87512e659b1/href</a></iframe><p>This is the main and only function we need to call to start loading data into Grakn.</p><p>What happens in this function, is as follows:</p><ol><li>A grakn instance is created, connected to the server we have running locally.</li><li>A session is created, connected to the keyspace phone_calls.</li><li>For each input object in inputs, we call the loadDataIntoGrakn(input, session). This will take care of loading the data as specified in the input object into our keyspace.</li><li>The session is closed.</li></ol><h4>loadDataIntoGrakn(input, session)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab3687d274c92da3860470b489d0fe35/href">https://medium.com/media/ab3687d274c92da3860470b489d0fe35/href</a></iframe><p>In order to load data from each file into Grakn, we need to:</p><ol><li>retrieve a list containing objects, each of which represents a data item. We do this by calling parseDataToObjects(input)</li><li>for each object in items: a) create a transaction tx, b) construct the graqlInsertQuery using the corresponding template function, c) run the query and d)commit the transaction.</li></ol><blockquote><strong>Note on creating and committing transactions: </strong>To avoid running out of memory, it’s recommended that every single query gets created and committed in a single transaction. However, for faster migration of large datasets, this can happen once for every <em>n</em> queries, where <em>n</em> is the maximum number of queries guaranteed to run on a single transaction.</blockquote><p>Before we move on to parsing the data into objects, let’s start with the template functions.</p><h3>The Template Functions</h3><p>Templates are simple functions that accept an object, representing a single data item. The values within this object fill in the blanks of the query template. The result will be a Graql insert query.</p><p>We need 4 of them. Let’s go through them one by one.</p><h4>companyTemplate</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83da2250615288543cd36907bf444692/href">https://medium.com/media/83da2250615288543cd36907bf444692/href</a></iframe><p>Example:</p><ul><li>Goes in: { name: &quot;Telecom&quot; }</li><li>Comes out: insert $company isa company has name &quot;Telecom&quot;;</li></ul><h4>personTemplate</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7a11d9b65a59bb00a075253aac331d6/href">https://medium.com/media/d7a11d9b65a59bb00a075253aac331d6/href</a></iframe><p>Example:</p><ul><li>Goes in: { phone_number: &quot;+44 091 xxx&quot; }</li><li>Comes out: insert $person has phone-number &quot;+44 091 xxx&quot;;</li></ul><p>or:</p><ul><li>Goes in: { firs-name: &quot;Jackie&quot;, last-name: &quot;Joe&quot;, city: &quot;Jimo&quot;, age: 77, phone_number: &quot;+00 091 xxx&quot;}</li><li>Comes out: insert $person has phone-number &quot;+44 091 xxx&quot; has first-name &quot;Jackie&quot; has last-name &quot;Joe&quot; has city &quot;Jimo&quot; has age 77;</li></ul><h4>contractTemplate</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cacb05f76e1f76e2a9581982ba8e209e/href">https://medium.com/media/cacb05f76e1f76e2a9581982ba8e209e/href</a></iframe><p>Example:</p><ul><li>Goes in: { company_name: &quot;Telecom&quot;, person_id: &quot;+00 091 xxx&quot; }</li><li>Comes out: match $company isa company has name &quot;Telecom&quot;; $customer isa person has phone-number &quot;+00 091 xxx&quot;; insert (provider: $company, customer: $customer) isa contract;</li></ul><h4>callTemplate</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b910e4a7475fb1b0a211dd3fd08d773f/href">https://medium.com/media/b910e4a7475fb1b0a211dd3fd08d773f/href</a></iframe><p>Example:</p><ul><li>Goes in: { caller_id: &quot;+44 091 xxx&quot;, callee_id: &quot;+00 091 xxx&quot;, started_at: 2018–08–10T07:57:51, duration: 148 }</li><li>Comes out: match $caller isa person has phone-number &quot;+44 091 xxx&quot;; $callee isa person has phone-number &quot;+00 091 xxx&quot;; insert $call(caller: $caller, callee: $callee) isa call; $call has started-at 2018–08–10T07:57:51; $call has duration 148;</li></ul><p>We’ve now created a template for each and all four concepts that were <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">previously</a> defined in the schema.</p><p>It’s time for the implementation of parseDataToObjects(input).</p><h3>DataFormat-specific implementation</h3><p>The implementation for parseDataToObjects(input) differs based on what format our data files have.</p><p>.csv, .json or .xml.</p><h4>Parsing CSV</h4><p>We will use Papaparse, a CSV (or delimited text) parser.</p><p>Via the terminal, while in the phone_calls directory, run npm install papaparse and require the module for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d55af5a4b5eabf29852f3188e3f9703/href">https://medium.com/media/5d55af5a4b5eabf29852f3188e3f9703/href</a></iframe><p>Moving on, we will write the implementation of parseDataToObjects(input) for parsing .csv files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a107583993484b4f7818b4fc447d3242/href">https://medium.com/media/a107583993484b4f7818b4fc447d3242/href</a></iframe><p>Besides this function, we need to make one more change.</p><p>Given the nature of CSV files, the object produced will have all the columns of the .csv file as its keys, even when the value is not there, it’ll be taken as a blank string.</p><p>For this reason, we need to change one line in our person_template function.</p><p>const isNotCustomer = typeof first_name === &quot;undefined&quot;;</p><p>becomes</p><p>const isNotCustomer = first_name === “”;</p><h4>Processing JSON</h4><p>We will use <a href="https://github.com/uhop/stream-json">stream-json</a> for custom JSON processing pipelines with a minimal memory footprint.</p><p>Via the terminal, while in the phone_calls directory, run npm install stream-json and require the modules for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0591eab2092ad3e0a521dc09e51a27b/href">https://medium.com/media/e0591eab2092ad3e0a521dc09e51a27b/href</a></iframe><p>Moving on, we will write the implementation of parseDataToObjects(input) for processing.json files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b26d79ca811e4819b9c7737870cd8c2d/href">https://medium.com/media/b26d79ca811e4819b9c7737870cd8c2d/href</a></iframe><h4>Parsing XML</h4><p>We will use <a href="https://github.com/assistunion/xml-stream">xml-stream</a>, an xml stream parser.</p><p>Via the terminal, while in the phone_calls directory, run npm install xml-stream and require the module for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23e5e91b38a16819e53ccad5f55723b2/href">https://medium.com/media/23e5e91b38a16819e53ccad5f55723b2/href</a></iframe><p>For parsing XML data, we need to know the target tag name. This needs to be specified for each data file in our inputs deceleration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/556955c0973dba3f5919aa5ef571a238/href">https://medium.com/media/556955c0973dba3f5919aa5ef571a238/href</a></iframe><p>And now for the implementation of parseDataToObjects(input) for parsing .xml files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/feee1c79a0e04dab9dd9d198c3d6e731/href">https://medium.com/media/feee1c79a0e04dab9dd9d198c3d6e731/href</a></iframe><h3>Putting it all together</h3><p>Here is how our migrate.js looks like for loading CSV data into Grakn, and find here are the ones for <a href="https://gist.github.com/sorsaffari/0a02bb8cb4b4f00cbbc89b9388da3c86">JSON</a> and <a href="https://gist.github.com/sorsaffari/11e7372deefc6b4c05629ec1d2d49ca8">XML</a> files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b3aa03ca4d86c86fce24b7bb9b8694b/href">https://medium.com/media/3b3aa03ca4d86c86fce24b7bb9b8694b/href</a></iframe><h3>Time to Load</h3><p>Run npm run migrate.js</p><p>Sit back, relax and watch the logs while the data starts pouring into Grakn.</p><h4>… so far with the migration</h4><p>We started off by setting up our project and positioning the data files.</p><p>Next we went on to set up the migration mechanism, one that was independent of the data format.</p><p>Then, we went ahead and wrote a template function for each concept. A template’s sole purpose was to construct a Graql insert query for each data item.</p><p>After that, we learned how files with different data formats can be parsed into Javascript objects.</p><p>Lastly, we ran npm run migrate.js which fired the buildPhoneCallGraph<em> </em>function with the given inputs. This loaded the data into our Grakn knowledge graph.</p><h3>Next: Query the Knowledge Graph</h3><p>When we <a href="https://blog.grakn.ai/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">modelled and loaded the schema into Grakn</a>, we had some insights in mind that we wanted to obtain from phone_calls; the knowledge graph.</p><p>Let’s revise:</p><ul><li>Since September 14th, which customers called person X?</li><li>Who are the people who have received a call from a London customer aged over 50 who has previously called someone aged under 20?</li><li>Who are the common contacts of customers X and Y?</li><li>Who are the customers who 1) have all called each other and 2) have all called person X at least once?</li><li>How does the average call duration among customers aged under 20 compare those aged over 40?</li></ul><p>For the rest of this post, we will go through each of these questions to:</p><ul><li>understand their business value,</li><li>write them as a statement,</li><li>write them in <a href="http://dev.grakn.ai/docs/query/overview">Graql</a>, and</li><li>assess their result.</li></ul><p>Make sure you have the <a href="http://dev.grakn.ai/docs/workbase/overview">Workbase</a> opened, while phone_calls selected as the keyspace (in the top-right hand corner).</p><p>Let’s begin.</p><h3>Since September 14th, which customers called person X?</h3><h4>The business value:</h4><pre>The person with phone number +86 921 547 9004 has been identified as a lead. We (company &quot;Telecom&quot;) would like to know which of our customers have been in contact with this person since September 14th. This will help us in converting this lead into a customer.</pre><h4>As a statement:</h4><pre>Get me the customers of company “Telecom” who called the target person with phone number +86 921 547 9004 from September 14th onwards.</pre><h4>In Graql:</h4><pre>match<br>  $customer isa person has phone-number $phone-number;<br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $customer, provider: $company) isa contract;<br>  $target isa person has phone-number &quot;+86 921 547 9004&quot;;<br>  (caller: $customer, callee: $target) isa call has started-at<br>  $started-at;<br>  $min-date == 2018-09-14T17:18:49; $started-at &gt; $min-date;<br>get $phone-number;</pre><h4>The result:</h4><pre>[ &#39;+62 107 530 7500&#39;, &#39;+370 351 224 5176&#39;, &#39;+54 398 559 0423&#39;, <br>  &#39;+7 690 597 4443&#39;,  &#39;+263 498 495 0617&#39;, &#39;+63 815 962 6097&#39;, <br>  &#39;+81 308 988 7153&#39;, &#39;+81 746 154 2598&#39;]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-BZNFArBfGfnRQ4_QrSYg.png" /><figcaption>Using Workbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IXifx70chmHSQq3GNyHyQ.png" /><figcaption><strong>USING THE GRAQL CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57f266743debfa345a04d7454342428b/href">https://medium.com/media/57f266743debfa345a04d7454342428b/href</a></iframe><h3>Who are the people who have received a call from a London customer aged over 50 who has previously called someone aged under 20?</h3><h4>The business value:</h4><pre>We (company &quot;Telecom&quot;) have received a number of harassment reports, which we suspect is caused by one individual. The only thing we know about the harasser is that he/she is aged roughly over 50 and lives in London. The reports have been made by young adults all aged under 20. We wonder if there is a pattern and so would like to speak to anyone who has received a call from a suspect, since the he/she potentially started harassing.</pre><h4>As a statement:</h4><pre>Get me the phone number of people who have received a call from a customer aged over 50 after the suspect made a call to a customer aged under 20.</pre><h4>In Graql:</h4><pre>match<br>  $suspect isa person has city &quot;London&quot;, has age &gt; 50;<br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $suspect, provider: $company) isa contract;<br>  $pattern-callee isa person has age &lt; 20;<br>  (caller: $suspect, callee: $pattern-callee) isa call <br>    has started at $pattern-call-date;<br>  $target isa person has phone-number $phone-number, <br>    has is-customer false;<br>  (caller: $suspect, callee: $target) isa call <br>    has started-at $target-call-date;<br>  $target-call-date &gt; $pattern-call-date;<br>get $phone-number;</pre><h4>The result:</h4><pre>[ &#39;+30 419 575 7546&#39;,  &#39;+86 892 682 0628&#39;, &#39;+1 254 875 4647&#39;, <br>  &#39;+351 272 414 6570&#39;, &#39;+33 614 339 0298&#39;, &#39;+86 922 760 0418&#39;, <br>  &#39;+86 825 153 5518&#39;,  &#39;+48 894 777 5173&#39;, &#39;+351 515 605 7915&#39;, <br>  &#39;+63 808 497 1769&#39;,  &#39;+27 117 258 4149&#39;, &#39;+86 202 257 8619&#39; ]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZzDuw6W6-BuHADXFi-Hug.png" /><figcaption>Using Workbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*awsYHq91nrJcacWo-IuEPg.png" /><figcaption><strong>USING THE GRAQL CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef61e0cbac92d6849fce365e853c9995/href">https://medium.com/media/ef61e0cbac92d6849fce365e853c9995/href</a></iframe><h3>Who are the common contacts of customers X and Y?</h3><h4>The business value:</h4><pre>The customer with phone number +7 171 898 0853 and +370 351 224 5176 have been identified as friends. We&#39;d like to know who their common contacts are in order to offer them a group promotion.</pre><h4>As a statement:</h4><pre>Get me the phone number of people who have received calls from both customer with phone number +7 171 898 0853 and customer with phone number +370 351 224 5176.</pre><h4>In Graql:</h4><pre>match<br>  $common-contact isa person has phone-number $phone-number;<br>  $customer-a isa person has phone-number &quot;+7 171 898 0853&quot;;<br>  $customer-b isa person has phone-number &quot;+370 351 224 5176&quot;;<br>  (caller: $customer-a, callee: $common-contact) isa call;<br>  (caller: $customer-b, callee: $common-contact) isa call;<br>get $phone-number;</pre><h4>The result:</h4><pre>[&#39;+86 892 682 0628&#39;, &#39;+54 398 559 0423&#39;]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mKLY5G1PEWFDe3KvRr0wzA.png" /><figcaption>Using Workbas</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sr6QtApU0GPqd-tdngcFA.png" /><figcaption><strong>USING THE GRAQL CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/693f7458ff3490b729e48bf048572e25/href">https://medium.com/media/693f7458ff3490b729e48bf048572e25/href</a></iframe><h3>Who are the customers who 1) have all called each other and 2) have all called person X at least once?</h3><h4>The business value:</h4><pre>The person with phone number +48 894 777 5173 has been identified as a lead. We (company &quot;Telecom&quot;) would like to know who his circle of  (customer) contacts are, so that we can encourage them in converting this lead to a customer.</pre><h4>As a statement:</h4><pre>Get me the phone phone number of all customers who have called each other as well the person with phone number +48 894 777 5173.</pre><h4>In Graql:</h4><pre>match<br>  $target isa person has phone-number &quot;+48 894 777 5173&quot;;<br>  $company isa company has name &quot;Telecom&quot;;<br>  $customer-a isa person has phone-number $phone-number-a;<br>  $customer-b isa person has phone-number $phone-number-b;<br>  (customer: $customer-a, provider: $company) isa contract;<br>  (customer: $customer-b, provider: $company) isa contract;<br>  (caller: $customer-a, callee: $customer-b) isa call;<br>  (caller: $customer-a, callee: $target) isa call;<br>  (caller: $customer-b, callee: $target) isa call;<br>get $phone-number-a, $phone-number-b;</pre><h4>The result:</h4><pre>[ &#39;+62 107 530 7500&#39;, &#39;+261 860 539 4754&#39;, &#39;+81 308 988 7153&#39; ]</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCp03VBYfU9V9LiQN1hVuQ.png" /><figcaption>Using Workbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqJv07bl577lw9XWwEDd5A.png" /><figcaption><strong>USING THE GRAQ CONSOLE</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5426483e6ba8ada4664cd626561f9c7d/href">https://medium.com/media/5426483e6ba8ada4664cd626561f9c7d/href</a></iframe><h3>How does the average call duration among customers aged under 20 compare with those aged over 40?</h3><h4>The business value:</h4><pre>In order to better understand our customers&#39; behaviour, we (company &quot;Telecom&quot;) like to know how the average phone call duration among those aged under 20 compares to those aged over 40.</pre><p>Two queries need to be executed to provide this insight.</p><h4>Query 1: aged under 20</h4><h4>As a statement:</h4><pre>Get me the average call duration among customers who have a contract with company &quot;Telecom&quot; and are aged under 20.</pre><h4>In Graql:</h4><pre>match <br>  $customer isa person has age &lt; 20; <br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $customer, provider: $company) isa contract;<br>  (caller: $customer, callee: $anyone) isa call has duration<br>  $duration; <br>aggregate mean $duration;</pre><h4>The result:</h4><pre>1348 seconds</pre><h4>Query 2: aged over 40</h4><h4>As a statement:</h4><pre>Get me the average call duration among customers who have a contract with company &quot;Telecom&quot; and are aged over 40.</pre><h4>In Graql:</h4><pre>match <br>  $customer isa person has age &gt; 40; <br>  $company isa company has name &quot;Telecom&quot;;<br>  (customer: $customer, provider: $company) isa contract;<br>  (caller: $customer, callee: $anyone) isa call has duration<br>  $duration; <br>  aggregate mean $duration;</pre><h4>The result:</h4><pre>1587 seconds</pre><h3>Try it yourself</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSjWMetuILbHT7vWVBjGxQ.png" /><figcaption><strong>USING THE GRAQL SHELL</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d675e25024ed0404442db04a37c2388/href">https://medium.com/media/3d675e25024ed0404442db04a37c2388/href</a></iframe><h3>👏 You’ve done it!</h3><p>Five Graql queries, each written in a few lines, answered all of our questions. Our imaginary client, Telecom, can now take these insights back to their team and, hopefully, use them responsibly to serve their customers. You are the one who made it happen!</p><h3>🚀 There is (always) more!</h3><p>This, by no means, should be the end of our phone_calls Grakn knowledge graph. Try the <a href="https://github.com/graknlabs/examples/tree/master/python/queries">interactive query executor</a> , play around with it and write your own <a href="http://dev.grakn.ai/docs/query/overview">Graql queries</a> to gain more interesting insights over this dataset.</p><p>Model the <a href="http://dev.grakn.ai/docs/schema/overview">schema</a> for your own brand new knowledge graph! Head to the <a href="http://dev.grakn.ai/docs">Grakn Documentation</a> and learn more about the cool things you can do with Grakn.</p><p><a href="https://grakn.ai/slack">Talk to us</a>, <a href="https://discuss.grakn.ai/">discuss</a> your ideas and <a href="https://github.com/graknlabs/grakn">contribute</a> to Grakn!</p><p>Stay tuned for more Grakn <a href="https://github.com/graknlabs/examples">examples</a> 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8261e5d210b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/whos-calling-grakn-node-js-client-migrate-csv-json-and-xml-query-the-knowledge-graph-d8261e5d210b">Who’s calling? Grakn Node.js client. Migrate (csv, json and xml) &amp; query the knowledge graph</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who’s calling? Grakn. Model and Load a schema into a knowledge graph]]></title>
            <link>https://medium.com/vaticle/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f18541faec89</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ontology]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 17:44:57 GMT</pubDate>
            <atom:updated>2022-03-29T17:07:31.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4sA2ZUjCflEPKcTiZtsfEw.png" /></figure><h4>This tutorial may be out of date against the latest version of Grakn. For the most up-to-date version of this tutorial, please refer to the <a href="http://dev.grakn.ai/docs/examples/phone-calls-overview">Grakn Documentation</a>.</h4><p>In this tutorial, our aim is to write a schema and load it into our knowledge graph; phone_calls. One that describes the reality of our dataset.</p><h3>The Dataset</h3><p>First off, let’s look at the dataset we are going to be working with. Simply put, we’re going to have:</p><p><strong>people</strong> who <strong>call </strong>each other. Those who make calls, have a <strong>contract</strong> with <strong>company</strong> “Telecom”.</p><p>People, calls, contracts and companies. That’s what we are dealing with. But what do we want to get out of this data?</p><h4>The insights</h4><p>The below insights will give us a better perspective of what else needs to be included in the dataset.</p><ul><li>Since September 14th, which customers called the person X?</li><li>Who are the people who have received a call from a London customer aged over 50 who has previously called someone aged under 20?</li><li>Who are the common contacts of customers X and Y?</li><li>Who are the customers who 1) have all called each other and 2) have all called person X at least once?</li><li>How does the average call duration among customers aged under 20 compare with those aged over 40?</li></ul><p>This is all we need for determining how our schema should be defined. Let’s break it down.</p><p>A <strong>company </strong>has a <strong>name</strong>, and can be the <strong>provider</strong> of a <strong>contract </strong>to a <strong>person</strong>, who then becomes a <strong>customer</strong>.</p><p>A <strong>person </strong>has a <strong>first and last name</strong>, an <strong>age</strong>, a <strong>city</strong> they live in, and a <strong>phone number</strong>. A person who doesn’t have a registered contract (not a customer) has only a <strong>phone number.</strong></p><p>A <strong>call, </strong>made from a <strong>person</strong> <strong>(caller)</strong> to another <strong>person</strong> <strong>(callee), </strong>has a <strong>duration </strong>as well as the <strong>date and time</strong> it’s been made.</p><h3>The Schema</h3><p>Now that we have a good understanding of our dataset, we can go ahead and write the schema for it.</p><p>But first, let’s visualise the reality of our dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*6zvF2DgVaA3rYomkS9nTqA.png" /></figure><p>By looking at this visualised schema, we can identify the <a href="http://www.vaticle.com/">Grakn</a> concepts.</p><blockquote>Everything that describes your domain in a Grakn knowledge graph is a <strong>concept</strong>. This includes the elements of the schema (namely types and roles, which we call schema concepts) and the actual data (which we simply call things; you can think of them as instances of types if you are the programmer kind of person).</blockquote><p><strong>call</strong> is of type <strong>relationship </strong>that has two role players:</p><ul><li><strong><em>person </em></strong><em>who plays the role of a </em><strong><em>caller</em></strong>, and</li><li>(another) <strong><em>person </em></strong><em>who plays the role of a </em><strong><em>callee.</em></strong></li></ul><p><strong>contract</strong> is also of type r<strong>elationship </strong>that has two role players:</p><ul><li><strong><em>company </em></strong><em>who plays the role of a </em><strong><em>provider</em></strong>, and</li><li><strong><em>person </em></strong><em>who plays the role of a </em><strong>customer</strong>.</li></ul><p><strong>company</strong> and <strong>person</strong> are of type <strong>entity</strong>.</p><p><strong><em>first-name</em></strong>, <strong><em>last-name</em></strong>, <strong><em>phone-number</em></strong>, <strong><em>city</em></strong>, <strong><em>age</em></strong>, <strong><em>started-at</em></strong> and <strong><em>duration</em></strong> are of type <strong>attribute</strong>.</p><p>That’s all well and good, but how do we get our knowledge graph to reflect this model?</p><h4>Time to talk Graql</h4><p>Open a new file in your favourite text editor, preferably one with syntax highlighting for Graql (.gql) files. Here are the ones for <a href="https://atom.io/packages/language-graql">atom</a>, <a href="https://marketplace.visualstudio.com/items?itemName=idealley.gql">visual studio code</a> and <a href="https://github.com/graknlabs/graql_syntax_sublime">sublime 3</a>.</p><p>You can define the elements of a Grakn schema in any order you wish. I personally prefer to start from the relationships, as I see them to be the source of interactions — where knowledge is derived from.</p><p>Any <strong>relationship</strong> relates to at least one <strong>role</strong> that is played by at least 2 <strong>concepts</strong>.</p><p>In our case, a <strong>call</strong> relates to <strong>caller</strong> played by a <strong>person</strong> and to <strong>callee </strong>played by another <strong>person</strong>.</p><p>Likewise for a <strong>contract</strong>. It relates to <strong>provider </strong>played by a <strong>company</strong> and to <strong>customer</strong> played by a <strong>person</strong>.</p><pre>define<br>  <br>  contract sub relationship,<br>    <strong>relates provider,<br>    relates customer;</strong></pre><pre>call sub relationship,<br>    <strong>relates caller,<br>    relates callee;</strong></pre><pre>company sub entity,<br>    <strong>plays provider;</strong></pre><pre>person sub entity,<br>    <strong>plays customer,<br>    plays caller,<br>    plays callee;</strong></pre><p>To define the attributes, we use the <strong>has</strong> keyword.</p><pre>define<br>  <br>  contract sub relationship,<br>    relates provider,<br>    relates customer;</pre><pre>call sub relationship,<br>    relates caller,<br>    relates callee,<br>    <strong>has started-at,<br>    has duration;</strong></pre><pre>company sub entity,<br>    plays provider,<br>    <strong>has name;</strong></pre><pre>person sub entity,<br>    plays customer,<br>    plays caller,<br>    plays callee,<br>    <strong>has first-name,<br>    has last-name,<br>    has phone-number,<br>    has city,<br>    has age,<br>    has is-customer;</strong></pre><p>Lastly, we need to define the type of each attribute.</p><pre>define<br>  <br>  contract sub relationship,<br>    relates provider,<br>    relates customer;</pre><pre>call sub relationship,<br>    relates caller,<br>    relates callee,<br>    has started-at,<br>    has duration;</pre><pre>company sub entity,<br>    plays provider,<br>    has name;</pre><pre>person sub entity,<br>    plays customer,<br>    plays caller,<br>    plays callee,<br>    has first-name,<br>    has last-name,<br>    has phone-number,<br>    has city,<br>    has age,<br>    has is-customer;<br>  <br><strong>  name sub attribute datatype string;<br>  started-at sub attribute datatype date;<br>  duration sub attribute datatype long;<br>  first-name sub attribute datatype string;<br>  last-name sub attribute datatype string;<br>  phone-number sub attribute datatype string;<br>  city sub attribute datatype string;<br>  age sub attribute datatype long;<br>  is-customer sub attribute datatype boolean;</strong></pre><p>Note that we don’t need to define any <em>id </em>attribute. Grakn takes care of that for us.</p><p>Save the schema.gql file. In a few minutes, we’ll have it loaded into a brand new Grakn keyspace.</p><h3>Load and test the schema</h3><p>So here it is, the schema for our phone_calls knowledge graph.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/619878caa1055cd1ecb6a6bbcc8a86d0/href">https://medium.com/media/619878caa1055cd1ecb6a6bbcc8a86d0/href</a></iframe><p>In order to load this schema in a keyspace, we first need to run the Grakn server.</p><p><strong>1 — </strong><a href="http://dev.grakn.ai/docs/running-grakn/install-and-run">Download Grakn</a></p><p>For the rest of these instructions, I will assume that you have downloaded the Grakn zip file and navigated into the unzipped folder via terminal.</p><p><strong>2 </strong>— Run the Grakn server:</p><pre>./grakn server start</pre><p><strong>3 </strong>— Load the schema into a Grakn keyspace. Run:</p><pre>./grakn console --keyspace phone_calls --file path/to/the/schema.gql</pre><p><strong>4 — </strong>Open the Graql console in interactive mode. Run:</p><pre>./grakn console --keyspace phone_calls</pre><p><strong>5 </strong>— Make sure the schema is properly defined in our newly created knowledge graph. While in the Graql console, run:</p><pre>match $x sub thing; get;</pre><p>The result should be as follows:</p><pre>{$x label thing;}<br>{$x label entity;}<br>{$x label relationship;}<br>{$x label attribute;}<br>{$x label company sub entity;}<br>{$x label person sub entity;}<br>{$x label call sub relationship;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot; sub relationship;}<br>{$x label contract sub relationship;}<br>{$x label name sub attribute;}<br>{$x label started-at sub attribute;}<br>{$x label age sub attribute;}<br>{$x label city sub attribute;}<br>{$x label last-name sub attribute;}<br>{$x label first-name sub attribute;}<br>{$x label duration sub attribute;}<br>{$x label phone-number sub attribute;}<br>{$x label is-customer sub attribute;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-started-at&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-first-name&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-city&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-name&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-duration&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-age&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-last-name&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-phone-number&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}<br>{$x label &quot;<a href="http://twitter.com/has">@has</a>-is-customer&quot; sub &quot;<a href="http://twitter.com/has">@has</a>-attribute&quot;;}</pre><h3>To Recap</h3><p>We started off by describing our dataset in the most natural way possible.</p><p>Next, we went on to visualise that dataset by how we perceive it in the real world.</p><p>Then, by identifying the Grakn concepts in the visualised schema, we went ahead and wrote our schema in Graql.</p><p>Lastly, we loaded the schema into a Grakn keyspace and ran a generic match query to ensure it was indeed loaded correctly.</p><h3>Next: Migrate data into Grakn and Query for insights</h3><p>Now that we have a model for our knowledge graph, aka. the schema, we can go ahead and migrate some actual data into it so that we can query for those insights.</p><h4>Time to make a choice</h4><p>Continue to migration with <a href="https://blog.grakn.ai/whos-calling-grakn-node-js-client-migrate-csv-json-and-xml-query-the-knowledge-graph-d8261e5d210b"><strong>Node.js</strong></a>, <a href="https://blog.grakn.ai/loading-data-and-querying-knowledge-from-a-grakn-knowledge-graph-using-the-python-client-b764a476cda8"><strong>Python</strong></a><strong> </strong>or <a href="https://blog.grakn.ai/loading-data-into-a-grakn-knowledge-graph-using-the-java-client-5f2f1a7f9903"><strong>Java</strong></a><strong>.</strong></p><p>Continue to query with <a href="https://blog.grakn.ai/whos-calling-grakn-node-js-client-migrate-csv-json-and-xml-query-the-knowledge-graph-d8261e5d210b#674c"><strong>Node.js</strong></a> or <a href="https://blog.grakn.ai/loading-data-and-querying-knowledge-from-a-grakn-knowledge-graph-using-the-python-client-b764a476cda8#674c"><strong>Python</strong></a> (coming soon: Java).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f18541faec89" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vaticle/whos-calling-grakn-model-and-load-a-schema-into-a-knowledge-graph-f18541faec89">Who’s calling? Grakn. Model and Load a schema into a knowledge graph</a> was originally published in <a href="https://medium.com/vaticle">TypeDB</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who’s Calling? Grakn Python client. Migrate (csv, json and xml) & query the knowledge graph]]></title>
            <link>https://medium.com/@sorsaffari/whos-calling-grakn-python-client-migrate-csv-json-and-xml-query-the-knowledge-graph-4af10788f4ae?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4af10788f4ae</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 14:19:01 GMT</pubDate>
            <atom:updated>2018-10-02T10:25:39.913Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wa55h_dhMA3l2KUIE4cQqw.jpeg" /></figure><h4>This post is now published under the<a href="http://blog.grakn.ai/"> Grakn Publication</a>. Click <a href="https://blog.grakn.ai/loading-data-and-querying-knowledge-from-a-grakn-knowledge-graph-using-the-python-client-b764a476cda8">here</a> to view the post.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4af10788f4ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who’s calling? Grakn Node.js client. Migrate (csv, json and xml) & query the knowledge graph]]></title>
            <link>https://medium.com/@sorsaffari/query-the-knowledge-graph-db30d7b4f4d8?source=rss-80ec376615c------2</link>
            <guid isPermaLink="false">https://medium.com/p/db30d7b4f4d8</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[grakn]]></category>
            <dc:creator><![CDATA[Soroush Saffari]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 14:18:16 GMT</pubDate>
            <atom:updated>2018-09-28T15:21:25.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppj7hNrX5JOrzLYf2yVnzQ.jpeg" /></figure><h4>This post is now published under the<a href="http://blog.grakn.ai/"> Grakn Publication</a>. Click <a href="https://blog.grakn.ai/whos-calling-grakn-node-js-client-migrate-csv-json-and-xml-query-the-knowledge-graph-d8261e5d210b">here</a> to view the post.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db30d7b4f4d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>