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

Whoops, The Numbers Are Wrong! Scaling Data Quality @ Netflix
Whoops, The Numbers Are Wrong! Scaling Data Quality @ NetflixWhoops, The Numbers Are Wrong! Scaling Data Quality @ Netflix
Whoops, The Numbers Are Wrong! Scaling Data Quality @ NetflixDataWorks Summit
 
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
 
Data Pipline Observability meetup
Data Pipline Observability meetup Data Pipline Observability meetup
Data Pipline Observability meetup Omid Vahdaty
 
Presto best practices for Cluster admins, data engineers and analysts
Presto best practices for Cluster admins, data engineers and analystsPresto best practices for Cluster admins, data engineers and analysts
Presto best practices for Cluster admins, data engineers and analystsShubham Tagra
 
NoSQL Graph Databases - Why, When and Where
NoSQL Graph Databases - Why, When and WhereNoSQL Graph Databases - Why, When and Where
NoSQL Graph Databases - Why, When and WhereEugene Hanikblum
 
Knowledge Graph Generation from Wikipedia in the Age of ChatGPT: Knowledge ...
Knowledge Graph Generation  from Wikipedia in the Age of ChatGPT:  Knowledge ...Knowledge Graph Generation  from Wikipedia in the Age of ChatGPT:  Knowledge ...
Knowledge Graph Generation from Wikipedia in the Age of ChatGPT: Knowledge ...Heiko Paulheim
 
Announcing Databricks Cloud (Spark Summit 2014)
Announcing Databricks Cloud (Spark Summit 2014)Announcing Databricks Cloud (Spark Summit 2014)
Announcing Databricks Cloud (Spark Summit 2014)Databricks
 
One Ontology, One Data Set, Multiple Shapes with SHACL
One Ontology, One Data Set, Multiple Shapes with SHACLOne Ontology, One Data Set, Multiple Shapes with SHACL
One Ontology, One Data Set, Multiple Shapes with SHACLConnected Data World
 
OPA APIs and Use Case Survey
OPA APIs and Use Case SurveyOPA APIs and Use Case Survey
OPA APIs and Use Case SurveyTorin Sandall
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HAharoonm
 
How to Take Advantage of an Enterprise Data Warehouse in the Cloud
How to Take Advantage of an Enterprise Data Warehouse in the CloudHow to Take Advantage of an Enterprise Data Warehouse in the Cloud
How to Take Advantage of an Enterprise Data Warehouse in the CloudDenodo
 
Data Modeling for MongoDB
Data Modeling for MongoDBData Modeling for MongoDB
Data Modeling for MongoDBMongoDB
 
An Introduction to SPARQL
An Introduction to SPARQLAn Introduction to SPARQL
An Introduction to SPARQLOlaf Hartig
 
Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020Julien Le Dem
 
Introduction to RDF & SPARQL
Introduction to RDF & SPARQLIntroduction to RDF & SPARQL
Introduction to RDF & SPARQLOpen Data Support
 
Best Practices for Building and Deploying Data Pipelines in Apache Spark
Best Practices for Building and Deploying Data Pipelines in Apache SparkBest Practices for Building and Deploying Data Pipelines in Apache Spark
Best Practices for Building and Deploying Data Pipelines in Apache SparkDatabricks
 

What's hot (20)

SHACL Overview
SHACL OverviewSHACL Overview
SHACL Overview
 
Whoops, The Numbers Are Wrong! Scaling Data Quality @ Netflix
Whoops, The Numbers Are Wrong! Scaling Data Quality @ NetflixWhoops, The Numbers Are Wrong! Scaling Data Quality @ Netflix
Whoops, The Numbers Are Wrong! Scaling Data Quality @ Netflix
 
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
 
Data Pipline Observability meetup
Data Pipline Observability meetup Data Pipline Observability meetup
Data Pipline Observability meetup
 
Nosql
NosqlNosql
Nosql
 
Migrating Oracle to PostgreSQL
Migrating Oracle to PostgreSQLMigrating Oracle to PostgreSQL
Migrating Oracle to PostgreSQL
 
Presto best practices for Cluster admins, data engineers and analysts
Presto best practices for Cluster admins, data engineers and analystsPresto best practices for Cluster admins, data engineers and analysts
Presto best practices for Cluster admins, data engineers and analysts
 
NoSQL Graph Databases - Why, When and Where
NoSQL Graph Databases - Why, When and WhereNoSQL Graph Databases - Why, When and Where
NoSQL Graph Databases - Why, When and Where
 
Knowledge Graph Generation from Wikipedia in the Age of ChatGPT: Knowledge ...
Knowledge Graph Generation  from Wikipedia in the Age of ChatGPT:  Knowledge ...Knowledge Graph Generation  from Wikipedia in the Age of ChatGPT:  Knowledge ...
Knowledge Graph Generation from Wikipedia in the Age of ChatGPT: Knowledge ...
 
Announcing Databricks Cloud (Spark Summit 2014)
Announcing Databricks Cloud (Spark Summit 2014)Announcing Databricks Cloud (Spark Summit 2014)
Announcing Databricks Cloud (Spark Summit 2014)
 
One Ontology, One Data Set, Multiple Shapes with SHACL
One Ontology, One Data Set, Multiple Shapes with SHACLOne Ontology, One Data Set, Multiple Shapes with SHACL
One Ontology, One Data Set, Multiple Shapes with SHACL
 
OPA APIs and Use Case Survey
OPA APIs and Use Case SurveyOPA APIs and Use Case Survey
OPA APIs and Use Case Survey
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
How to Take Advantage of an Enterprise Data Warehouse in the Cloud
How to Take Advantage of an Enterprise Data Warehouse in the CloudHow to Take Advantage of an Enterprise Data Warehouse in the Cloud
How to Take Advantage of an Enterprise Data Warehouse in the Cloud
 
Data Modeling for MongoDB
Data Modeling for MongoDBData Modeling for MongoDB
Data Modeling for MongoDB
 
An Introduction to SPARQL
An Introduction to SPARQLAn Introduction to SPARQL
An Introduction to SPARQL
 
Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020Data lineage and observability with Marquez - subsurface 2020
Data lineage and observability with Marquez - subsurface 2020
 
Introduction to RDF & SPARQL
Introduction to RDF & SPARQLIntroduction to RDF & SPARQL
Introduction to RDF & SPARQL
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
 
Best Practices for Building and Deploying Data Pipelines in Apache Spark
Best Practices for Building and Deploying Data Pipelines in Apache SparkBest Practices for Building and Deploying Data Pipelines in Apache Spark
Best Practices for Building and Deploying Data Pipelines in Apache Spark
 

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
 
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
 
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
 
Pandora Paper Leaks With TypeDB
 Pandora Paper Leaks With TypeDB Pandora Paper Leaks With TypeDB
Pandora Paper Leaks With TypeDBVaticle
 
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
 

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
 
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
 
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
 
Pandora Paper Leaks With TypeDB
 Pandora Paper Leaks With TypeDB Pandora Paper Leaks With TypeDB
Pandora Paper Leaks With TypeDB
 
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
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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?