Skip to content

Commit

Permalink
Added methods for Category node, working on methods for Article node now
Browse files Browse the repository at this point in the history
  • Loading branch information
tyjch committed May 17, 2018
1 parent 5546c4a commit c878f00
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 10 deletions.
93 changes: 86 additions & 7 deletions Notebooks/Testing/data.ipynb
Expand Up @@ -18,9 +18,7 @@
"metadata": {},
"outputs": [],
"source": [
"graph = Database().default_graph\n",
"node = Node(\"First Node\")\n",
"wiki = WikiNode(\"Article\")"
"graph = Database().default_graph"
]
},
{
Expand All @@ -29,17 +27,69 @@
"metadata": {},
"outputs": [],
"source": [
"graph.create(node)"
"wikinode = WikiNode(\"Set theory\", \"Article\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"graph.delete_all()\n",
"graph.create(wikinode)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": []
"source": [
"database = Database()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2018, 4, 18, 18, 23, 23, 246000)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"database.store_creation_time"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'116a9f3c9365c5c3'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"database.store_id"
]
},
{
"cell_type": "code",
Expand All @@ -65,7 +115,36 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.5.3"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": true
}
},
"nbformat": 4,
Expand Down
1 change: 0 additions & 1 deletion neo/graph/graph.py
@@ -1,6 +1,5 @@
from py2neo import Database


def get_default_database():
default_graph = Database.default_graph
return default_graph
20 changes: 18 additions & 2 deletions neo/graph/wikipedia.py
Expand Up @@ -56,18 +56,22 @@ def __init__(self, title, label):

if label not in WikiNode.WIKILABELS:
print("{} is not permitted as a label for this class", label)

else:
# TODO: Check if a node with the same primary key-value pair exists in the graph first

Node.__init__(self, title, label)
TimeMixin.__init__(self)
DefaultGraphMixin.__init__(self)


class Article(WikiNode):

def __init__(self, title):
property_depth = Property()
has_article = RelatedTo("Article")

def __init__(self, title, depth=0):
super(Article, self).__init__(title, "Article")
self.property_depth = depth

def get_categories(self):

Expand All @@ -89,6 +93,7 @@ class Category(WikiNode):

property_depth = Property()
has_category = RelatedTo("Category")
has_article = RelatedTo("Article")

def __init__(self, title, depth=0):
super(Category, self).__init__(title, "Category")
Expand All @@ -104,3 +109,14 @@ def get_categories(self, graph):

self.has_category.add(category)
graph.push(self)

def get_articles(self, graph):

category = WikipediaPage(self.property_title)

for page in category.links:
article = Article(page, depth=self.property_depth + 1)
graph.push(article)

self.has_article.add(article)
graph.push(self)

0 comments on commit c878f00

Please sign in to comment.