SlideShare a Scribd company logo
1 of 24
Download to read offline
TypeDB Academy | Inference with Rules
Agenda
a. Review concepts and patterns of TypeDB rules, written in TypeQL
b. Modelling functional relationships between concept and schema
c. Present the structure, requirements, implications and techniques
d. Discuss as a group some applications of rules in the wild
Deductive Reasoning
Reasoning via backward-chaining allows us to reach a conclusion based on the facts we already
have.
Composed of two parts:
1. Condition
2. Conclusion
The Condition checks the facts we currently have, to see if we can reach the conclusion.
Example
Condition - When it’s raining outside
Conclusion - I should take an umbrella
Other types of reasoning (not supported)
There are other types of reasoning that don’t lead to definite outcomes,
and so are less suitable to be implemented by a knowledge graph.
Inductive Reasoning
It rained every day for the last week, so it will probably rain tomorrow
Abductive Reasoning
The ground is wet, therefore it probably rained
What’s the value of automated reasoning?
Automated reasoning can be re-computed on-the-fly and can take care of
logical reasoning beyond human capabilities:
• vertically in terms of number of rules applied / chained
• horizontally over big data
How does TypeDB’s reasoner work?
• Takes in rules, defined the same way as schema and applies those rules at query-time.
• The conclusions from reasoning are held in memory, not written to disk – necessary as the causes
of the rule conditions may change. This dynamic nature means:
• reasoned facts are never stale
• the size on disk doesn’t increase with the number of facts that can be reasoned over
(could be exponential)
• Works in first-order logic
• Operates on a set
• Doesn’t accept functions as predicates.
Where might we use reasoner?
Thinking about our own domain, where or what questions
might we make use of reasoner, to answer?
A TypeDB rule
Rules in TypeQL are used to determine the Conditions that lead to a
Conclusion.
When a query is made, TypeDB checks (recursively) whether any of the
stored rules apply. If they do, then the Conclusion is inferred.
Rules are defined and undefined the same way as schema:
Since rules don’t have any interdependencies, they can be added and removed easily.
Writing rules
define
rule my-rule-label:
when {
## the condition, a TypeQL pattern (the body)
} then {
## the conclusion, a TypeQL pattern (the head)
};
undefine rule my-rule-label;
Writing rules
As an example:
define
mutual-friendship sub relation,
relates mutual-friend,
relates one-degree-friend;
rule people-have-mutual-friends:
when {
$r1($p1, $p2) isa friendship;
$r2($p2, $p3) isa friendship;
} then {
(one-degree-friend: $p1,
one-degree-friend: $p3,
mutual-friend: $p2) isa mutual-friendship;
};
Writing rules
This lets us quickly find the mutual friends between two people. It’s triggered
when we ask for something in the rule body; e.g. a mutual-friendship:
match
$p1 isa person, has full-name “Ahmed Frazier”;
$p2 isa person, has full-name $n;
$p3 isa person, has full-name “Raphael Santos”;
(one-degree-friend: $p1,
one-degree-friend: $p3,
mutual-friend: $p2) isa mutual-friendship;
get $n; limit 5;
What can we infer?
What can go in the then {…}, the conclusion of a rule?
Relations
then { (sibling: $x, sibling: $y) isa siblings; };
Attribute ownership of a constant attribute
then { $p has nickname ”Anne”; };
Attribute ownership of a variable attribute
then { $p has $is-graduated; };
When to use rules?
We use rules:
• To abbreviate a commonly asked query.
• To test a hypothesis which has multiple possible causes (or to future-proof for
this scenario): and get an explanation for why.
• this moves application logic to the database for cleaner code and easier
maintenance.
• To create chained logic and recursive queries, which aren’t otherwise possible.
• For investigation.
• Rules are very flexible, so they can be used to try things that you don’t want to
persist.
• To create complex types that you can’t with schema alone.
Abbreviating queries to find insights
It is clear that reproducing the Condition of this rule is not trivial, so we can
certainly justify writing a rule to yield this insight for us.
rule events-overlap:
when {
$e1 isa periodic-event;
$e1 has start-date $sd1, has end-date $ed1
$e2 isa periodic-event;
$e2 has start-date $sd2, has end-date $ed2
$sd2 > $sd1; $sd2 < $ed1;
not {$e1 is $e2; };
} then {
(overlapped-event: $e1,
overlapped-event: $e2) isa event-
overlapping;
};
rule public-permission
when {
(shared-content: $sc) isa public-sharing;
$pu isa public-user;
}, then {
(permitted-content: $sc,
(permission-grantee: $pu) isa permitted-to-see;
};
rule friends-permission:
when {
(shared-content: $sc, shared-by: $sb) isa friends-sharing;
(friend: $sb, $f) isa friendship;
}, then {
(permitted-content: $sc,
(permission-grantee: $f) isa permitted-to-see;
};
rule author-permission:
when {
(shared-content: $sc, shared-by: $sb) isa sharing;
}, then {
(permitted-content: $sc,
(permission-grantee: $sb) isa permitted-to-see;
};
Content
permissions
Hypothesis testing
This means we can now ask a simple question (our hypothesis), and TypeDB
will tell us whether the conclusion is true. We can ask who is permitted to see
a specific post:
match
$sb isa person, has email $e;
$sc isa post, has identifier “$per-3-pos-1”;
$p(content: $sc, grantee: $sb) isa content-permission;
Inferring more than one atom
Multiple atoms in the rule head is in the feature roadmap for TypeDB.
For now, we need as many rules as things we want to infer.
A couple more notes on rules
We can’t use disjunctions (or) in rule bodies. Instead, split each of the
conditions in { condition-1 }; or { condition-2 }; into separate rules.
Remember that rules can be written programmatically, so we can auto-
generate them for disjunctions with lots of conditions.
Let’s write some rules
Derive a rule that states that the owner of a social-group must therefore be a
member of that social-group.
Let’s write some rules
Derive a rule that states that the owner of a social-group must therefore be a
member of that social-group.
rule owner-is-always-member:
when {
$group isa social-group;
(owner: $owner, owned-group: $group) isa group-
ownership;
} then {
(member: $owner, membership-group: $group) isa
membership;
};
Let’s write some rules
Derive a rule that states that people who are married are therefore friends.
Let’s write some rules
Derive a rule that states that people who are married are therefore friends.
rule married-couples-are-friends:
when {
$mar(wife: $w, husband: $h) isa marriage;
} then {
(friend: $w, friend: $h) isa friendship;
};
Discussion
What are some concepts that we might want to infer
within our own domain?
Thank you!!

More Related Content

What's hot

Introduction to Linked Data 1/5
Introduction to Linked Data 1/5Introduction to Linked Data 1/5
Introduction to Linked Data 1/5Juan Sequeda
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
The Apache Solr Semantic Knowledge Graph
The Apache Solr Semantic Knowledge GraphThe Apache Solr Semantic Knowledge Graph
The Apache Solr Semantic Knowledge GraphTrey Grainger
 
Knowledge Graphs for Supply Chain Operations.pdf
Knowledge Graphs for Supply Chain Operations.pdfKnowledge Graphs for Supply Chain Operations.pdf
Knowledge Graphs for Supply Chain Operations.pdfVaticle
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQLAmazon Web Services
 
An intro to GraphQL
An intro to GraphQLAn intro to GraphQL
An intro to GraphQLvaluebound
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQLSquareboat
 
Elastic search Walkthrough
Elastic search WalkthroughElastic search Walkthrough
Elastic search WalkthroughSuhel Meman
 
Unifying Space Mission Knowledge with NLP & Knowledge Graph
Unifying Space Mission Knowledge with NLP & Knowledge GraphUnifying Space Mission Knowledge with NLP & Knowledge Graph
Unifying Space Mission Knowledge with NLP & Knowledge GraphVaticle
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
Pandora Paper Leaks With TypeDB
 Pandora Paper Leaks With TypeDB Pandora Paper Leaks With TypeDB
Pandora Paper Leaks With TypeDBVaticle
 
Introduction to Knowledge Graphs
Introduction to Knowledge GraphsIntroduction to Knowledge Graphs
Introduction to Knowledge Graphsmukuljoshi
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQLTomasz Bak
 
Deep Neural Methods for Retrieval
Deep Neural Methods for RetrievalDeep Neural Methods for Retrieval
Deep Neural Methods for RetrievalBhaskar Mitra
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST APIAmilaSilva13
 

What's hot (20)

Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Introduction to Linked Data 1/5
Introduction to Linked Data 1/5Introduction to Linked Data 1/5
Introduction to Linked Data 1/5
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
The Apache Solr Semantic Knowledge Graph
The Apache Solr Semantic Knowledge GraphThe Apache Solr Semantic Knowledge Graph
The Apache Solr Semantic Knowledge Graph
 
GraphQL
GraphQLGraphQL
GraphQL
 
Knowledge Graphs for Supply Chain Operations.pdf
Knowledge Graphs for Supply Chain Operations.pdfKnowledge Graphs for Supply Chain Operations.pdf
Knowledge Graphs for Supply Chain Operations.pdf
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQL
 
An intro to GraphQL
An intro to GraphQLAn intro to GraphQL
An intro to GraphQL
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Elastic search Walkthrough
Elastic search WalkthroughElastic search Walkthrough
Elastic search Walkthrough
 
ShEx vs SHACL
ShEx vs SHACLShEx vs SHACL
ShEx vs SHACL
 
Unifying Space Mission Knowledge with NLP & Knowledge Graph
Unifying Space Mission Knowledge with NLP & Knowledge GraphUnifying Space Mission Knowledge with NLP & Knowledge Graph
Unifying Space Mission Knowledge with NLP & Knowledge Graph
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Pandora Paper Leaks With TypeDB
 Pandora Paper Leaks With TypeDB Pandora Paper Leaks With TypeDB
Pandora Paper Leaks With TypeDB
 
Introduction to Knowledge Graphs
Introduction to Knowledge GraphsIntroduction to Knowledge Graphs
Introduction to Knowledge Graphs
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
Deep Neural Methods for Retrieval
Deep Neural Methods for RetrievalDeep Neural Methods for Retrieval
Deep Neural Methods for Retrieval
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST API
 

Similar to TypeDB Academy | Inference with Rules

CrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataRaphael do Vale
 
A wiki for_business_rules_in_open_vocabulary_executable_english
A wiki for_business_rules_in_open_vocabulary_executable_englishA wiki for_business_rules_in_open_vocabulary_executable_english
A wiki for_business_rules_in_open_vocabulary_executable_englishAdrian Walker
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl Lyndon White
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.Jason Hearne-McGuiness
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodbMohammed Ragab
 
CS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduceCS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduceJ Singh
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principlesdeonpmeyer
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD WorkshopWolfram Arnold
 

Similar to TypeDB Academy | Inference with Rules (20)

Ruleby
RulebyRuleby
Ruleby
 
CrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked data
 
A wiki for_business_rules_in_open_vocabulary_executable_english
A wiki for_business_rules_in_open_vocabulary_executable_englishA wiki for_business_rules_in_open_vocabulary_executable_english
A wiki for_business_rules_in_open_vocabulary_executable_english
 
EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Programming in the large
Programming in the largeProgramming in the large
Programming in the large
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
CAP: Scaling, HA
CAP: Scaling, HACAP: Scaling, HA
CAP: Scaling, HA
 
Lesson 19
Lesson 19Lesson 19
Lesson 19
 
AI Lesson 19
AI Lesson 19AI Lesson 19
AI Lesson 19
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
Hw fdb(2)
Hw fdb(2)Hw fdb(2)
Hw fdb(2)
 
Hw fdb(2)
Hw fdb(2)Hw fdb(2)
Hw fdb(2)
 
Data science unit3
Data science unit3Data science unit3
Data science unit3
 
CS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduceCS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduce
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 

More from Vaticle

Building Biomedical Knowledge Graphs for In-Silico Drug Discovery
Building Biomedical Knowledge Graphs for In-Silico Drug DiscoveryBuilding Biomedical Knowledge Graphs for In-Silico Drug Discovery
Building Biomedical Knowledge Graphs for In-Silico Drug DiscoveryVaticle
 
Loading Huge Amounts of Data
Loading Huge Amounts of DataLoading Huge Amounts of Data
Loading Huge Amounts of DataVaticle
 
Natural Language Interface to Knowledge Graph
Natural Language Interface to Knowledge GraphNatural Language Interface to Knowledge Graph
Natural Language Interface to Knowledge GraphVaticle
 
A Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security KnowledgeA Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security KnowledgeVaticle
 
The Next Big Thing in AI - Causality
The Next Big Thing in AI - CausalityThe Next Big Thing in AI - Causality
The Next Big Thing in AI - CausalityVaticle
 
Building a Cyber Threat Intelligence Knowledge Graph
Building a Cyber Threat Intelligence Knowledge GraphBuilding a Cyber Threat Intelligence Knowledge Graph
Building a Cyber Threat Intelligence Knowledge GraphVaticle
 
Building a Distributed Database with Raft.pdf
Building a Distributed Database with Raft.pdfBuilding a Distributed Database with Raft.pdf
Building a Distributed Database with Raft.pdfVaticle
 
Enabling the Computational Future of Biology.pdf
Enabling the Computational Future of Biology.pdfEnabling the Computational Future of Biology.pdf
Enabling the Computational Future of Biology.pdfVaticle
 
Beyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQLBeyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQLVaticle
 
Comparing Semantic Web Technologies to TypeDB
Comparing Semantic Web Technologies to TypeDBComparing Semantic Web Technologies to TypeDB
Comparing Semantic Web Technologies to TypeDBVaticle
 
Reasoner, Meet Actors | TypeDB's Native Reasoning Engine
Reasoner, Meet Actors | TypeDB's Native Reasoning EngineReasoner, Meet Actors | TypeDB's Native Reasoning Engine
Reasoner, Meet Actors | TypeDB's Native Reasoning EngineVaticle
 
Strongly Typed Data for Machine Learning
Strongly Typed Data for Machine LearningStrongly Typed Data for Machine Learning
Strongly Typed Data for Machine LearningVaticle
 
Open World Robotics
Open World RoboticsOpen World Robotics
Open World RoboticsVaticle
 
Combining Causal and Knowledge Modeling for Digital Transformation
Combining Causal and Knowledge Modeling for Digital TransformationCombining Causal and Knowledge Modeling for Digital Transformation
Combining Causal and Knowledge Modeling for Digital TransformationVaticle
 
How can we complete a Knowledge Graph?
How can we complete a Knowledge Graph?How can we complete a Knowledge Graph?
How can we complete a Knowledge Graph?Vaticle
 
Text-Mined Data in a Knowledge Graph
Text-Mined Data in a Knowledge GraphText-Mined Data in a Knowledge Graph
Text-Mined Data in a Knowledge GraphVaticle
 
Introduction to Knowledge Graphs with Grakn and Graql
Introduction to Knowledge Graphs with Grakn and Graql Introduction to Knowledge Graphs with Grakn and Graql
Introduction to Knowledge Graphs with Grakn and Graql Vaticle
 
Power of the Run Graph
Power of the Run GraphPower of the Run Graph
Power of the Run GraphVaticle
 
Increase Self Awareness on Robotic Systems
Increase Self Awareness on Robotic SystemsIncrease Self Awareness on Robotic Systems
Increase Self Awareness on Robotic SystemsVaticle
 
Grounding Conversational AI in a Knowledge Base
Grounding Conversational AI in a Knowledge BaseGrounding Conversational AI in a Knowledge Base
Grounding Conversational AI in a Knowledge BaseVaticle
 

More from Vaticle (20)

Building Biomedical Knowledge Graphs for In-Silico Drug Discovery
Building Biomedical Knowledge Graphs for In-Silico Drug DiscoveryBuilding Biomedical Knowledge Graphs for In-Silico Drug Discovery
Building Biomedical Knowledge Graphs for In-Silico Drug Discovery
 
Loading Huge Amounts of Data
Loading Huge Amounts of DataLoading Huge Amounts of Data
Loading Huge Amounts of Data
 
Natural Language Interface to Knowledge Graph
Natural Language Interface to Knowledge GraphNatural Language Interface to Knowledge Graph
Natural Language Interface to Knowledge Graph
 
A Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security KnowledgeA Data Modelling Framework to Unify Cyber Security Knowledge
A Data Modelling Framework to Unify Cyber Security Knowledge
 
The Next Big Thing in AI - Causality
The Next Big Thing in AI - CausalityThe Next Big Thing in AI - Causality
The Next Big Thing in AI - Causality
 
Building a Cyber Threat Intelligence Knowledge Graph
Building a Cyber Threat Intelligence Knowledge GraphBuilding a Cyber Threat Intelligence Knowledge Graph
Building a Cyber Threat Intelligence Knowledge Graph
 
Building a Distributed Database with Raft.pdf
Building a Distributed Database with Raft.pdfBuilding a Distributed Database with Raft.pdf
Building a Distributed Database with Raft.pdf
 
Enabling the Computational Future of Biology.pdf
Enabling the Computational Future of Biology.pdfEnabling the Computational Future of Biology.pdf
Enabling the Computational Future of Biology.pdf
 
Beyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQLBeyond SQL - Comparing SQL to TypeQL
Beyond SQL - Comparing SQL to TypeQL
 
Comparing Semantic Web Technologies to TypeDB
Comparing Semantic Web Technologies to TypeDBComparing Semantic Web Technologies to TypeDB
Comparing Semantic Web Technologies to TypeDB
 
Reasoner, Meet Actors | TypeDB's Native Reasoning Engine
Reasoner, Meet Actors | TypeDB's Native Reasoning EngineReasoner, Meet Actors | TypeDB's Native Reasoning Engine
Reasoner, Meet Actors | TypeDB's Native Reasoning Engine
 
Strongly Typed Data for Machine Learning
Strongly Typed Data for Machine LearningStrongly Typed Data for Machine Learning
Strongly Typed Data for Machine Learning
 
Open World Robotics
Open World RoboticsOpen World Robotics
Open World Robotics
 
Combining Causal and Knowledge Modeling for Digital Transformation
Combining Causal and Knowledge Modeling for Digital TransformationCombining Causal and Knowledge Modeling for Digital Transformation
Combining Causal and Knowledge Modeling for Digital Transformation
 
How can we complete a Knowledge Graph?
How can we complete a Knowledge Graph?How can we complete a Knowledge Graph?
How can we complete a Knowledge Graph?
 
Text-Mined Data in a Knowledge Graph
Text-Mined Data in a Knowledge GraphText-Mined Data in a Knowledge Graph
Text-Mined Data in a Knowledge Graph
 
Introduction to Knowledge Graphs with Grakn and Graql
Introduction to Knowledge Graphs with Grakn and Graql Introduction to Knowledge Graphs with Grakn and Graql
Introduction to Knowledge Graphs with Grakn and Graql
 
Power of the Run Graph
Power of the Run GraphPower of the Run Graph
Power of the Run Graph
 
Increase Self Awareness on Robotic Systems
Increase Self Awareness on Robotic SystemsIncrease Self Awareness on Robotic Systems
Increase Self Awareness on Robotic Systems
 
Grounding Conversational AI in a Knowledge Base
Grounding Conversational AI in a Knowledge BaseGrounding Conversational AI in a Knowledge Base
Grounding Conversational AI in a Knowledge Base
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

TypeDB Academy | Inference with Rules

  • 1. TypeDB Academy | Inference with Rules
  • 2. Agenda a. Review concepts and patterns of TypeDB rules, written in TypeQL b. Modelling functional relationships between concept and schema c. Present the structure, requirements, implications and techniques d. Discuss as a group some applications of rules in the wild
  • 3. Deductive Reasoning Reasoning via backward-chaining allows us to reach a conclusion based on the facts we already have. Composed of two parts: 1. Condition 2. Conclusion The Condition checks the facts we currently have, to see if we can reach the conclusion. Example Condition - When it’s raining outside Conclusion - I should take an umbrella
  • 4. Other types of reasoning (not supported) There are other types of reasoning that don’t lead to definite outcomes, and so are less suitable to be implemented by a knowledge graph. Inductive Reasoning It rained every day for the last week, so it will probably rain tomorrow Abductive Reasoning The ground is wet, therefore it probably rained
  • 5. What’s the value of automated reasoning? Automated reasoning can be re-computed on-the-fly and can take care of logical reasoning beyond human capabilities: • vertically in terms of number of rules applied / chained • horizontally over big data
  • 6. How does TypeDB’s reasoner work? • Takes in rules, defined the same way as schema and applies those rules at query-time. • The conclusions from reasoning are held in memory, not written to disk – necessary as the causes of the rule conditions may change. This dynamic nature means: • reasoned facts are never stale • the size on disk doesn’t increase with the number of facts that can be reasoned over (could be exponential) • Works in first-order logic • Operates on a set • Doesn’t accept functions as predicates.
  • 7. Where might we use reasoner? Thinking about our own domain, where or what questions might we make use of reasoner, to answer?
  • 8. A TypeDB rule Rules in TypeQL are used to determine the Conditions that lead to a Conclusion. When a query is made, TypeDB checks (recursively) whether any of the stored rules apply. If they do, then the Conclusion is inferred.
  • 9. Rules are defined and undefined the same way as schema: Since rules don’t have any interdependencies, they can be added and removed easily. Writing rules define rule my-rule-label: when { ## the condition, a TypeQL pattern (the body) } then { ## the conclusion, a TypeQL pattern (the head) }; undefine rule my-rule-label;
  • 10. Writing rules As an example: define mutual-friendship sub relation, relates mutual-friend, relates one-degree-friend; rule people-have-mutual-friends: when { $r1($p1, $p2) isa friendship; $r2($p2, $p3) isa friendship; } then { (one-degree-friend: $p1, one-degree-friend: $p3, mutual-friend: $p2) isa mutual-friendship; };
  • 11. Writing rules This lets us quickly find the mutual friends between two people. It’s triggered when we ask for something in the rule body; e.g. a mutual-friendship: match $p1 isa person, has full-name “Ahmed Frazier”; $p2 isa person, has full-name $n; $p3 isa person, has full-name “Raphael Santos”; (one-degree-friend: $p1, one-degree-friend: $p3, mutual-friend: $p2) isa mutual-friendship; get $n; limit 5;
  • 12. What can we infer? What can go in the then {…}, the conclusion of a rule? Relations then { (sibling: $x, sibling: $y) isa siblings; }; Attribute ownership of a constant attribute then { $p has nickname ”Anne”; }; Attribute ownership of a variable attribute then { $p has $is-graduated; };
  • 13. When to use rules? We use rules: • To abbreviate a commonly asked query. • To test a hypothesis which has multiple possible causes (or to future-proof for this scenario): and get an explanation for why. • this moves application logic to the database for cleaner code and easier maintenance. • To create chained logic and recursive queries, which aren’t otherwise possible. • For investigation. • Rules are very flexible, so they can be used to try things that you don’t want to persist. • To create complex types that you can’t with schema alone.
  • 14. Abbreviating queries to find insights It is clear that reproducing the Condition of this rule is not trivial, so we can certainly justify writing a rule to yield this insight for us. rule events-overlap: when { $e1 isa periodic-event; $e1 has start-date $sd1, has end-date $ed1 $e2 isa periodic-event; $e2 has start-date $sd2, has end-date $ed2 $sd2 > $sd1; $sd2 < $ed1; not {$e1 is $e2; }; } then { (overlapped-event: $e1, overlapped-event: $e2) isa event- overlapping; };
  • 15. rule public-permission when { (shared-content: $sc) isa public-sharing; $pu isa public-user; }, then { (permitted-content: $sc, (permission-grantee: $pu) isa permitted-to-see; }; rule friends-permission: when { (shared-content: $sc, shared-by: $sb) isa friends-sharing; (friend: $sb, $f) isa friendship; }, then { (permitted-content: $sc, (permission-grantee: $f) isa permitted-to-see; }; rule author-permission: when { (shared-content: $sc, shared-by: $sb) isa sharing; }, then { (permitted-content: $sc, (permission-grantee: $sb) isa permitted-to-see; }; Content permissions
  • 16. Hypothesis testing This means we can now ask a simple question (our hypothesis), and TypeDB will tell us whether the conclusion is true. We can ask who is permitted to see a specific post: match $sb isa person, has email $e; $sc isa post, has identifier “$per-3-pos-1”; $p(content: $sc, grantee: $sb) isa content-permission;
  • 17. Inferring more than one atom Multiple atoms in the rule head is in the feature roadmap for TypeDB. For now, we need as many rules as things we want to infer.
  • 18. A couple more notes on rules We can’t use disjunctions (or) in rule bodies. Instead, split each of the conditions in { condition-1 }; or { condition-2 }; into separate rules. Remember that rules can be written programmatically, so we can auto- generate them for disjunctions with lots of conditions.
  • 19. Let’s write some rules Derive a rule that states that the owner of a social-group must therefore be a member of that social-group.
  • 20. Let’s write some rules Derive a rule that states that the owner of a social-group must therefore be a member of that social-group. rule owner-is-always-member: when { $group isa social-group; (owner: $owner, owned-group: $group) isa group- ownership; } then { (member: $owner, membership-group: $group) isa membership; };
  • 21. Let’s write some rules Derive a rule that states that people who are married are therefore friends.
  • 22. Let’s write some rules Derive a rule that states that people who are married are therefore friends. rule married-couples-are-friends: when { $mar(wife: $w, husband: $h) isa marriage; } then { (friend: $w, friend: $h) isa friendship; };
  • 23. Discussion What are some concepts that we might want to infer within our own domain?