Skip to content

Commit

Permalink
Merge pull request #130 from DeanLight/add_example_to_review
Browse files Browse the repository at this point in the history
add sample_question to review by new persons
  • Loading branch information
DeanLight authored Oct 23, 2023
2 parents e6b3869 + 96620f5 commit 7ccb4f6
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nbs/sample_data/story.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Once upon a time, there was a little girl named Aria Walker. Aria is the daughter of Owen. Owen was a kind and caring father who adored his daughter's laughter and curiosity.
In the neighboring town, there lived a cheerful boy named Eliana. Eliana's eyes sparkled with innocence, Owen is the father of Eliana.
Owen cherished every moment spent with Eliana, teaching her valuable life lessons and nurturing her dreams.
One sunny day, Aria gave birth to a wonderful girl called Mila. Mila is the daughter of Aria, Aria, watched over her with unwavering love and pride.
Aria and Mila formed an instant bond, becoming the best of friends and had a blossoming friendship.

As the years passed, Mila grew into a confident young girl, thanks to the support and encouragement of her mother, Aria. Mila, in turn,
became a caring sibling to her little brother,Owen is the father of Caleb. Their bond was unbreakable,
and they shared countless adventures together under the watchful eyes of their mother.

Across the village, there lived a young girl named Lila. Lila was a spirited and curious child, Lila is the daughter of Benjamin, she was
always seeking new adventures in the world around her.
Her father, Benjamin Smith, was a wise and gentle man who cherished his daughter's laughter and inquisitive nature.
Benjamin had another child, Daniel is the child of Benjamin, Yaer is the parent of Benjamin.
143 changes: 143 additions & 0 deletions nbs/sample_question.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After familiarizing yourself with the syntax of rgxlog, <br>\n",
"let's explore another example that highlights the power of this declarative language. <br>\n",
"given a story.txt file which contains in between its lines parent-child information, the information is provided as follows: <br>\n",
"1- X is the parent/father of Y <br>\n",
"2- Y is the child/daughter of X\n",
"\n",
"The story also has some last names.\n",
"The task is to identify the last name of all individuals.\n",
"It's important to note that you don't have access to individual last names, but you can deduce them by constructing family trees based on the information provided in the story.\n",
"\n",
"Here is the first line of the story as an example:\n",
"```plaintext\n",
"Once upon a time, there was a little girl named Aria Walker. Aria is the daughter of Owen.\n",
"```\n",
"What you should deduce from this line is that Owen is the parent of Aria as it matches the first template of provided information (Y is the daughter of X), <br>\n",
"and since Aria's name was given along with her lastname, <br>\n",
"you should also conclude that Owen's last name is also Walker.\n",
"\n",
"Take a couple of minutes to think a solution for this problem.\n",
"---\n",
"\n",
"Now that you understand the complexity of deducing last names based on family trees and extracting the parent-child relationships using Python, <br>\n",
"let us show you how easily we can do that by incorporating rgxlog into the equation.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Installation NLP failed\n",
"cargo or rustup are not installed in $PATH. please install rust: https://rustup.rs/\n"
]
}
],
"source": [
"import rgxlog"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"printing results for query 'parent(X, Y)':\n",
" X | Y\n",
"----------+----------\n",
" Aria | Mila\n",
" Benjamin | Daniel\n",
" Benjamin | Lila\n",
" Owen | Aria\n",
" Owen | Caleb\n",
" Owen | Eliana\n",
" Yaer | Benjamin\n",
"\n",
"printing results for query 'lastname(X, Y)':\n",
" X | Y\n",
"----------+--------\n",
" Aria | Walker\n",
" Benjamin | Smith\n",
"\n"
]
}
],
"source": [
"%%rgxlog\n",
"story = read(\"sample_data/story.txt\")\n",
"parent(X,Y) <- py_rgx_string(story, \"(\\w+)\\s+is\\s+the\\s+daughter\\s+of\\s+(\\w+)\") -> (Y,X)\n",
"parent(X,Y) <- py_rgx_string(story, \"(\\w+)\\s+is\\s+the\\s+child\\s+of\\s+(\\w+)\") -> (Y,X)\n",
"parent(X,Y) <- py_rgx_string(story, \"(\\w+)\\s+is\\s+the\\s+parent\\s+of\\s+(\\w+)\") -> (X,Y)\n",
"parent(X,Y) <- py_rgx_string(story, \"(\\w+)\\s+is\\s+the\\s+father\\s+of\\s+(\\w+)\") -> (X,Y)\n",
"lastname(X,Y) <- py_rgx_string(story, \"([A-Z][a-z]+)\\s([A-Z][a-z]+)\") -> (X,Y)\n",
"?parent(X,Y)\n",
"?lastname(X,Y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deducing Last Names Based on Family Trees with rgxlog\n",
"\n",
"The following rgxlog code provides a simple yet powerful way to deduce the last name of each person based on the family tree information extracted to the parent relation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"printing results for query 'Family(X, Y)':\n",
" X | Y\n",
"--------+----------\n",
" Smith | Benjamin\n",
" Smith | Daniel\n",
" Smith | Lila\n",
" Smith | Yaer\n",
" Walker | Aria\n",
" Walker | Caleb\n",
" Walker | Eliana\n",
" Walker | Mila\n",
" Walker | Owen\n",
"\n"
]
}
],
"source": [
"%%rgxlog\n",
"Family(X,Y) <- lastname(Y,X)\n",
"Family(X,Y) <- Family(X,Z), parent(Y,Z)\n",
"Family(X,Y) <- Family(X,Z), parent(Z,Y)\n",
"?Family(X,Y)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions rgxlog/stanford-corenlp-4.1.0.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><title>Google Drive - Virus scan warning</title><meta http-equiv="content-type" content="text/html; charset=utf-8"/><style nonce="pATd33V1Kc6Z6wyxdedh0g">.goog-inline-block{position:relative;display:-moz-inline-box;display:inline-block}* html .goog-inline-block{display:inline}*:first-child+html .goog-inline-block{display:inline}.goog-link-button{position:relative;color:#15c;text-decoration:underline;cursor:pointer}.goog-link-button-disabled{color:#ccc;text-decoration:none;cursor:default}body{color:#222;font:normal 13px/1.4 arial,sans-serif;margin:0}.grecaptcha-badge{visibility:hidden}.uc-main{padding-top:50px;text-align:center}#uc-dl-icon{display:inline-block;margin-top:16px;padding-right:1em;vertical-align:top}#uc-text{display:inline-block;max-width:68ex;text-align:left}.uc-error-caption,.uc-warning-caption{color:#222;font-size:16px}#uc-download-link{text-decoration:none}.uc-name-size a{color:#15c;text-decoration:none}.uc-name-size a:visited{color:#61c;text-decoration:none}.uc-name-size a:active{color:#d14836;text-decoration:none}.uc-footer{color:#777;font-size:11px;padding-bottom:5ex;padding-top:5ex;text-align:center}.uc-footer a{color:#15c}.uc-footer a:visited{color:#61c}.uc-footer a:active{color:#d14836}.uc-footer-divider{color:#ccc;width:100%}sentinel{}</style><link rel="icon" href="//ssl.gstatic.com/docs/doclist/images/drive_2022q3_32dp.png"/></head><body><div class="uc-main"><div id="uc-dl-icon" class="image-container"><div class="drive-sprite-aux-download-file"></div></div><div id="uc-text"><p class="uc-warning-caption">Google Drive can't scan this file for viruses.</p><p class="uc-warning-subcaption"><span class="uc-name-size"><a href="/open?id=1QixGiHD2mHKuJtB69GHDQA0wTyXtHzjl">stanford-corenlp-4.1.0.zip</a> (481M)</span> is too large for Google to scan for viruses. Would you still like to download this file?</p><form id="download-form" action="https://docs.google.com/uc?export=download&amp;id=1QixGiHD2mHKuJtB69GHDQA0wTyXtHzjl&amp;confirm=t&amp;uuid=4ff14ae9-44a3-41db-8604-0722b071395e" method="post"><input type="submit" id="uc-download-link" class="goog-inline-block jfk-button jfk-button-action" value="Download anyway"/></form></div></div><div class="uc-footer"><hr class="uc-footer-divider"></div></body></html>

0 comments on commit 7ccb4f6

Please sign in to comment.