diff --git a/Demo_graph.ipynb b/Demo_graph.ipynb index c8f87cc6e..b6b053977 100644 --- a/Demo_graph.ipynb +++ b/Demo_graph.ipynb @@ -47,7 +47,7 @@ "metadata": {}, "outputs": [], "source": [ - "input_article_one = \"\"\" n the nicest possible way, Britons have always been a bit silly about animals. “Keeping pets, for the English, is not so much a leisure activity as it is an entire way of life,” wrote the anthropologist Kate Fox in Watching the English, nearly 20 years ago. Our dogs, in particular, have been an acceptable outlet for emotions and impulses we otherwise keep strictly controlled – our latent desire to be demonstratively affectionate, to be silly and chat to strangers. If this seems like an exaggeration, consider the different reactions you’d get if you struck up a conversation with someone in a park with a dog, versus someone on the train.\n", + "input_article_one = \"\"\" In the nicest possible way, Britons have always been a bit silly about animals. “Keeping pets, for the English, is not so much a leisure activity as it is an entire way of life,” wrote the anthropologist Kate Fox in Watching the English, nearly 20 years ago. Our dogs, in particular, have been an acceptable outlet for emotions and impulses we otherwise keep strictly controlled – our latent desire to be demonstratively affectionate, to be silly and chat to strangers. If this seems like an exaggeration, consider the different reactions you’d get if you struck up a conversation with someone in a park with a dog, versus someone on the train.\n", "\n", "Indeed, British society has been set up to accommodate these four-legged ambassadors. In the UK – unlike Australia, say, or New Zealand – dogs are not just permitted on public transport but often openly encouraged. Many pubs and shops display waggish signs, reading, “Dogs welcome, people tolerated”, and have treat jars on their counters. The other day, as I was waiting outside a cafe with a friend’s dog, the barista urged me to bring her inside.\n", "\n", @@ -1108,7 +1108,7 @@ "\n", "# Convert NetworkX graph to a Pandas DataFrame\n", "edges = nx.to_pandas_edgelist(B)\n", - "graphistry.register(api=3, username='Vasilije1990', password='Q@HLdgv5SMUsGxy') \n", + "graphistry.register(api=3, username='Vasilije1990', password='') \n", "\n", "# Visualize the graph\n", "graphistry.edges(edges, 'source', 'target').plot()" @@ -1353,7 +1353,7 @@ "\n", "# Convert NetworkX graph to a Pandas DataFrame\n", "edges = nx.to_pandas_edgelist(R)\n", - "graphistry.register(api=3, username='Vasilije1990', password='Q@HLdgv5SMUsGxy') \n", + "graphistry.register(api=3, username='Vasilije1990', password='') \n", "\n", "# Visualize the graph\n", "graphistry.edges(edges, 'source', 'target').plot()" @@ -2449,9 +2449,7 @@ "output_type": "execute_result" } ], - "source": [ - "unique_layer_uuids" - ] + "source": [] }, { "cell_type": "code", @@ -2464,6 +2462,38 @@ " " ] }, + { + "cell_type": "code", + "execution_count": 459, + "id": "8e517772-d4eb-4e7a-9393-1ea695020e65", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'27a76d52-5b5e-4e8e-8726-29be55c8b2f1',\n", + " '48c1a502-48b1-4240-87ac-6558d41e1b6f',\n", + " '4ef6847a-7036-4861-8df6-a209c53038ca',\n", + " '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n", + " '7b147696-3654-4e4c-b177-da5a1b44a2c0',\n", + " '92ae1b09-3dfb-4e0b-920d-83341d1d8c7b',\n", + " '97597864-a11a-4058-b854-8f21864c7e06',\n", + " 'b40f5ed5-45cf-43f5-902c-d4928743f8fd',\n", + " 'c306c248-bbab-44a9-9ae2-448f992e415c',\n", + " 'dbcbc6c6-db82-48f3-8fa9-e3d372ff3483',\n", + " 'e81660f7-b9a2-4266-a468-404a49b05888',\n", + " 'f3b1dd35-0640-40a0-a664-fb037aeb43c7'}" + ] + }, + "execution_count": 459, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unique_layer_uuids" + ] + }, { "cell_type": "code", "execution_count": 360, @@ -4486,92 +4516,437 @@ }, { "cell_type": "code", - "execution_count": 445, - "id": "217fcdd1-e1f7-48f3-a835-cfd003bd6da9", + "execution_count": 453, + "id": "0c33237a-fee9-4480-81cc-d17b5ec497bf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'27a76d52-5b5e-4e8e-8726-29be55c8b2f1',\n", + " '48c1a502-48b1-4240-87ac-6558d41e1b6f',\n", + " '4ef6847a-7036-4861-8df6-a209c53038ca',\n", + " '771e3cc9-fb2f-422e-a8f8-e067d6b44e34',\n", + " '7b147696-3654-4e4c-b177-da5a1b44a2c0',\n", + " '92ae1b09-3dfb-4e0b-920d-83341d1d8c7b',\n", + " '97597864-a11a-4058-b854-8f21864c7e06',\n", + " 'b40f5ed5-45cf-43f5-902c-d4928743f8fd',\n", + " 'c306c248-bbab-44a9-9ae2-448f992e415c',\n", + " 'dbcbc6c6-db82-48f3-8fa9-e3d372ff3483',\n", + " 'e81660f7-b9a2-4266-a468-404a49b05888',\n", + " 'f3b1dd35-0640-40a0-a664-fb037aeb43c7'}" + ] + }, + "execution_count": 453, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unique_layer_uuids" + ] + }, + { + "cell_type": "code", + "execution_count": 491, + "id": "1992d379-9dab-4839-a33a-21861c8c8864", "metadata": {}, "outputs": [], "source": [ - "def get_relevant_content_categories_from_graph(graph, classifier_categories, weight_threshold=0.9):\n", - " \"\"\" Gets relevant content categories from the graph \"\"\"\n", - " filtered_nodes = []\n", - " target_neighbors = []\n", + "def find_relevant_chunks(query,unique_layer_uuids):\n", + " out = []\n", + " for id in unique_layer_uuids:\n", + " print(id)\n", + " print(query)\n", + " result = qdrant_search(id, query)\n", "\n", - " # Iterate through each node and its attributes in the graph\n", - " for node, attrs in graph.nodes(data=True):\n", - " for category in relevant_categories.dict()['cognitive_subgroups']:\n", - "\n", - " if category['name'] in node:\n", - " print(node)\n", - "\n", - " target_relationship_type = 'detail'\n", + " if result:\n", + " result_ = [ result_.id for result_ in result]\n", + " score_ = [ result_.score for result_ in result]\n", " \n", - " # Initialize a list to hold the neighbors connected by the target relationship type\n", - " \n", - " \n", - " # Iterate over all edges connected to the target node\n", - " for neighbor in graph.neighbors(node):\n", - " \n", - " # Get the edge data between target node and its neighbor\n", - " edge_data = graph.get_edge_data(node, neighbor)\n", + " out.append([result_, score_])\n", "\n", - " try:\n", - " val= edge_data[0]['relationship']\n", - " \n", - " except:\n", - " val = ''\n", - " \n", - " # Check if the edge has the desired relationship type\n", - " if val == target_relationship_type:\n", - " target_neighbors.append(neighbor)\n", - " return target_neighbors\n", + " return out\n", " " ] }, { "cell_type": "code", - "execution_count": 447, - "id": "f974c87e-4117-4f93-a96c-e4fcd741aed9", + "execution_count": 492, + "id": "139bb41c-ef21-4558-9142-eae912a56c58", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Natural Language Text:Personal narratives and stories\n" + "f3b1dd35-0640-40a0-a664-fb037aeb43c7\n", + "uk\n", + "[]\n", + "c306c248-bbab-44a9-9ae2-448f992e415c\n", + "uk\n", + "[]\n", + "dbcbc6c6-db82-48f3-8fa9-e3d372ff3483\n", + "uk\n", + "[]\n", + "e81660f7-b9a2-4266-a468-404a49b05888\n", + "uk\n", + "[]\n", + "92ae1b09-3dfb-4e0b-920d-83341d1d8c7b\n", + "uk\n", + "[]\n", + "27a76d52-5b5e-4e8e-8726-29be55c8b2f1\n", + "uk\n", + "[]\n", + "4ef6847a-7036-4861-8df6-a209c53038ca\n", + "uk\n", + "[]\n", + "7b147696-3654-4e4c-b177-da5a1b44a2c0\n", + "uk\n", + "[]\n", + "97597864-a11a-4058-b854-8f21864c7e06\n", + "uk\n", + "[ScoredPoint(id='48191bec-b329-460e-8de3-7957ffa9909c', version=0, score=0.25039859785303464, payload={'meta': \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\"}, vector=None, shard_key=None), ScoredPoint(id='41a19992-d932-47c3-b1dc-41c4e673ab43', version=0, score=0.23113449570846986, payload={'meta': 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022'}, vector=None, shard_key=None), ScoredPoint(id='58fc3b86-be82-4d50-9578-2b157924ef23', version=0, score=0.2287030038880753, payload={'meta': 'In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs'}, vector=None, shard_key=None)]\n", + "48c1a502-48b1-4240-87ac-6558d41e1b6f\n", + "uk\n", + "[]\n", + "b40f5ed5-45cf-43f5-902c-d4928743f8fd\n", + "uk\n", + "[]\n", + "771e3cc9-fb2f-422e-a8f8-e067d6b44e34\n", + "uk\n", + "[]\n" ] } ], "source": [ - "example_context = get_relevant_content_categories_from_graph(CONNECTED_GRAPH, relevant_categories)" + "val = find_relevant_chunks('uk', unique_layer_uuids)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "2e81754a-2a2c-4a51-a678-5fff298d9fe7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 514, + "id": "aedb2c4b-1af6-4663-8a7d-cf8bbfb3dc77", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "def fetch_context(CONNECTED_GRAPH, id):\n", + " relevant_context = []\n", + " for n,attr in CONNECTED_GRAPH.nodes(data=True):\n", + " if id in n:\n", + " for n_, attr_ in CONNECTED_GRAPH.nodes(data=True):\n", + " relevant_layer = attr['layer_uuid']\n", + "\n", + " if attr_.get('layer_uuid') == relevant_layer:\n", + " print(attr_['description'])\n", + " relevant_context.append(attr_['description'])\n", + "\n", + " return relevant_context\n", + "\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 515, + "id": "4f17da0f-749e-4543-9213-24bdaa31a85b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "48191bec-b329-460e-8de3-7957ffa9909c\n", + "In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs\n", + "Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability\n", + "Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\n", + "Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains\n", + "The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022\n", + "England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics\n", + "There is a concerning trend of treating living beings, particularly popular 'designer' dog breeds, as commodities rather than sentient beings\n", + "The cultural shift in Britain towards treating pets as substitutes for children, favoring aesthetics over the animal's natural function and well-being\n", + "Consumerism in pet care is escalating in the UK with a significant increase in unnecessary spending on pets, including trends and luxury items\n", + "Pets are often indulged with unnecessary treats and services that do not align with their genuine needs or desires, indicative of human emotional solace through consumption\n", + "Modern lifestyles with busy schedules are causing dogs to live monotonous lives, leading to behavioral problems that are often placated by trivial indulgences\n", + "Proper pet care advocates for prioritizing pets' quality of life and well-being over anthropomorphic indulgences and misguided expressions of affection\n", + "Kate Fox, an anthropologist who described Britons' affection towards pets as a way of life in her book 'Watching the English'\n", + "Dogs serve as an outlet for emotions and social engagement for Britons\n", + "In the UK, dogs are accepted and encouraged in various public spaces like transport, pubs, and shops\n", + "Despite societal changes, the passion for animals in the UK has been consistent\n", + "The COVID-19 pandemic led to a surge in pet ownership, increasing the number of dogs in the UK\n", + "'A dog is for life, not just for Christmas' is a slogan by Dogs Trust charity to advocate responsible pet ownership\n", + "The number of dog attacks in England and Wales saw a significant rise\n", + "Certain dog breeds are increasingly perceived as commodities, particularly 'designer' breeds\n", + "Consumer spending on pets in the UK has increased, extending to non-essential items and services\n", + "Many dogs experience lack of socialization and extended periods of isolation due to modern human schedules\n", + "Ensuring the well-being of pets should be a priority, demanding sacrifices and quality care from the owners\n", + "Britons have a significant and emotional connection with animals, particularly dogs.\n", + "Kate Fox, an anthropologist who wrote about the English way of life with pets.\n", + "Number of pet dogs in the UK increased from about nine million to 13 million between 2019 and 2022.\n", + "In the UK, dogs are often encouraged to accompany their owners in public places such as pubs and shops.\n", + "The number of dog attacks recorded by police in England and Wales rose by more than a third between 2018 and 2022.\n", + "Pets, particularly dogs, are increasingly being treated as commodities rather than sentient beings.\n", + "Popularity of designer breeds like French bulldogs and pugs, which often suffer due to their physical features.\n", + "Controversial American XL bully dogs are sought after as a signifier of masculinity.\n", + "Pets are increasingly being treated as substitutes for children, altering the traditional British perspective of valuing dogs for their natural qualities.\n", + "Spending on pets in the UK has more than doubled in the past decade, reaching nearly £10bn in the previous year.\n", + "Rise in dog-friendly establishments like restaurants, theaters, and even churches, catering to dog owners more than the dogs themselves.\n", + "Many dogs suffer from daily deprivation and lack engagement due to their owner's busy schedules.\n", + "Behavioral issues in dogs often stem from insufficient exercise, supervision, and consistent routines.\n", + "41a19992-d932-47c3-b1dc-41c4e673ab43\n", + "In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs\n", + "Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability\n", + "Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\n", + "Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains\n", + "The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022\n", + "England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics\n", + "There is a concerning trend of treating living beings, particularly popular 'designer' dog breeds, as commodities rather than sentient beings\n", + "The cultural shift in Britain towards treating pets as substitutes for children, favoring aesthetics over the animal's natural function and well-being\n", + "Consumerism in pet care is escalating in the UK with a significant increase in unnecessary spending on pets, including trends and luxury items\n", + "Pets are often indulged with unnecessary treats and services that do not align with their genuine needs or desires, indicative of human emotional solace through consumption\n", + "Modern lifestyles with busy schedules are causing dogs to live monotonous lives, leading to behavioral problems that are often placated by trivial indulgences\n", + "Proper pet care advocates for prioritizing pets' quality of life and well-being over anthropomorphic indulgences and misguided expressions of affection\n", + "Kate Fox, an anthropologist who described Britons' affection towards pets as a way of life in her book 'Watching the English'\n", + "Dogs serve as an outlet for emotions and social engagement for Britons\n", + "In the UK, dogs are accepted and encouraged in various public spaces like transport, pubs, and shops\n", + "Despite societal changes, the passion for animals in the UK has been consistent\n", + "The COVID-19 pandemic led to a surge in pet ownership, increasing the number of dogs in the UK\n", + "'A dog is for life, not just for Christmas' is a slogan by Dogs Trust charity to advocate responsible pet ownership\n", + "The number of dog attacks in England and Wales saw a significant rise\n", + "Certain dog breeds are increasingly perceived as commodities, particularly 'designer' breeds\n", + "Consumer spending on pets in the UK has increased, extending to non-essential items and services\n", + "Many dogs experience lack of socialization and extended periods of isolation due to modern human schedules\n", + "Ensuring the well-being of pets should be a priority, demanding sacrifices and quality care from the owners\n", + "Britons have a significant and emotional connection with animals, particularly dogs.\n", + "Kate Fox, an anthropologist who wrote about the English way of life with pets.\n", + "Number of pet dogs in the UK increased from about nine million to 13 million between 2019 and 2022.\n", + "In the UK, dogs are often encouraged to accompany their owners in public places such as pubs and shops.\n", + "The number of dog attacks recorded by police in England and Wales rose by more than a third between 2018 and 2022.\n", + "Pets, particularly dogs, are increasingly being treated as commodities rather than sentient beings.\n", + "Popularity of designer breeds like French bulldogs and pugs, which often suffer due to their physical features.\n", + "Controversial American XL bully dogs are sought after as a signifier of masculinity.\n", + "Pets are increasingly being treated as substitutes for children, altering the traditional British perspective of valuing dogs for their natural qualities.\n", + "Spending on pets in the UK has more than doubled in the past decade, reaching nearly £10bn in the previous year.\n", + "Rise in dog-friendly establishments like restaurants, theaters, and even churches, catering to dog owners more than the dogs themselves.\n", + "Many dogs suffer from daily deprivation and lack engagement due to their owner's busy schedules.\n", + "Behavioral issues in dogs often stem from insufficient exercise, supervision, and consistent routines.\n", + "58fc3b86-be82-4d50-9578-2b157924ef23\n", + "In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs\n", + "Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability\n", + "Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\n", + "Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains\n", + "The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022\n", + "England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics\n", + "There is a concerning trend of treating living beings, particularly popular 'designer' dog breeds, as commodities rather than sentient beings\n", + "The cultural shift in Britain towards treating pets as substitutes for children, favoring aesthetics over the animal's natural function and well-being\n", + "Consumerism in pet care is escalating in the UK with a significant increase in unnecessary spending on pets, including trends and luxury items\n", + "Pets are often indulged with unnecessary treats and services that do not align with their genuine needs or desires, indicative of human emotional solace through consumption\n", + "Modern lifestyles with busy schedules are causing dogs to live monotonous lives, leading to behavioral problems that are often placated by trivial indulgences\n", + "Proper pet care advocates for prioritizing pets' quality of life and well-being over anthropomorphic indulgences and misguided expressions of affection\n", + "Kate Fox, an anthropologist who described Britons' affection towards pets as a way of life in her book 'Watching the English'\n", + "Dogs serve as an outlet for emotions and social engagement for Britons\n", + "In the UK, dogs are accepted and encouraged in various public spaces like transport, pubs, and shops\n", + "Despite societal changes, the passion for animals in the UK has been consistent\n", + "The COVID-19 pandemic led to a surge in pet ownership, increasing the number of dogs in the UK\n", + "'A dog is for life, not just for Christmas' is a slogan by Dogs Trust charity to advocate responsible pet ownership\n", + "The number of dog attacks in England and Wales saw a significant rise\n", + "Certain dog breeds are increasingly perceived as commodities, particularly 'designer' breeds\n", + "Consumer spending on pets in the UK has increased, extending to non-essential items and services\n", + "Many dogs experience lack of socialization and extended periods of isolation due to modern human schedules\n", + "Ensuring the well-being of pets should be a priority, demanding sacrifices and quality care from the owners\n", + "Britons have a significant and emotional connection with animals, particularly dogs.\n", + "Kate Fox, an anthropologist who wrote about the English way of life with pets.\n", + "Number of pet dogs in the UK increased from about nine million to 13 million between 2019 and 2022.\n", + "In the UK, dogs are often encouraged to accompany their owners in public places such as pubs and shops.\n", + "The number of dog attacks recorded by police in England and Wales rose by more than a third between 2018 and 2022.\n", + "Pets, particularly dogs, are increasingly being treated as commodities rather than sentient beings.\n", + "Popularity of designer breeds like French bulldogs and pugs, which often suffer due to their physical features.\n", + "Controversial American XL bully dogs are sought after as a signifier of masculinity.\n", + "Pets are increasingly being treated as substitutes for children, altering the traditional British perspective of valuing dogs for their natural qualities.\n", + "Spending on pets in the UK has more than doubled in the past decade, reaching nearly £10bn in the previous year.\n", + "Rise in dog-friendly establishments like restaurants, theaters, and even churches, catering to dog owners more than the dogs themselves.\n", + "Many dogs suffer from daily deprivation and lack engagement due to their owner's busy schedules.\n", + "Behavioral issues in dogs often stem from insufficient exercise, supervision, and consistent routines.\n" + ] + } + ], + "source": [ + "context = []\n", + "\n", + "for v in val[0][0]:\n", + " print(v)\n", + " context.append(fetch_context(CONNECTED_GRAPH, id=v))" + ] + }, + { + "cell_type": "code", + "execution_count": 516, + "id": "1007d1a9-19c4-4d02-a187-ad7c1c514e9d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs',\n", + " 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability',\n", + " \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\",\n", + " 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains',\n", + " 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022',\n", + " 'England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics',\n", + " \"There is a concerning trend of treating living beings, particularly popular 'designer' dog breeds, as commodities rather than sentient beings\",\n", + " \"The cultural shift in Britain towards treating pets as substitutes for children, favoring aesthetics over the animal's natural function and well-being\",\n", + " 'Consumerism in pet care is escalating in the UK with a significant increase in unnecessary spending on pets, including trends and luxury items',\n", + " 'Pets are often indulged with unnecessary treats and services that do not align with their genuine needs or desires, indicative of human emotional solace through consumption',\n", + " 'Modern lifestyles with busy schedules are causing dogs to live monotonous lives, leading to behavioral problems that are often placated by trivial indulgences',\n", + " \"Proper pet care advocates for prioritizing pets' quality of life and well-being over anthropomorphic indulgences and misguided expressions of affection\",\n", + " \"Kate Fox, an anthropologist who described Britons' affection towards pets as a way of life in her book 'Watching the English'\",\n", + " 'Dogs serve as an outlet for emotions and social engagement for Britons',\n", + " 'In the UK, dogs are accepted and encouraged in various public spaces like transport, pubs, and shops',\n", + " 'Despite societal changes, the passion for animals in the UK has been consistent',\n", + " 'The COVID-19 pandemic led to a surge in pet ownership, increasing the number of dogs in the UK',\n", + " \"'A dog is for life, not just for Christmas' is a slogan by Dogs Trust charity to advocate responsible pet ownership\",\n", + " 'The number of dog attacks in England and Wales saw a significant rise',\n", + " \"Certain dog breeds are increasingly perceived as commodities, particularly 'designer' breeds\",\n", + " 'Consumer spending on pets in the UK has increased, extending to non-essential items and services',\n", + " 'Many dogs experience lack of socialization and extended periods of isolation due to modern human schedules',\n", + " 'Ensuring the well-being of pets should be a priority, demanding sacrifices and quality care from the owners',\n", + " 'Britons have a significant and emotional connection with animals, particularly dogs.',\n", + " 'Kate Fox, an anthropologist who wrote about the English way of life with pets.',\n", + " 'Number of pet dogs in the UK increased from about nine million to 13 million between 2019 and 2022.',\n", + " 'In the UK, dogs are often encouraged to accompany their owners in public places such as pubs and shops.',\n", + " 'The number of dog attacks recorded by police in England and Wales rose by more than a third between 2018 and 2022.',\n", + " 'Pets, particularly dogs, are increasingly being treated as commodities rather than sentient beings.',\n", + " 'Popularity of designer breeds like French bulldogs and pugs, which often suffer due to their physical features.',\n", + " 'Controversial American XL bully dogs are sought after as a signifier of masculinity.',\n", + " 'Pets are increasingly being treated as substitutes for children, altering the traditional British perspective of valuing dogs for their natural qualities.',\n", + " 'Spending on pets in the UK has more than doubled in the past decade, reaching nearly £10bn in the previous year.',\n", + " 'Rise in dog-friendly establishments like restaurants, theaters, and even churches, catering to dog owners more than the dogs themselves.',\n", + " \"Many dogs suffer from daily deprivation and lack engagement due to their owner's busy schedules.\",\n", + " 'Behavioral issues in dogs often stem from insufficient exercise, supervision, and consistent routines.'],\n", + " ['In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs',\n", + " 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability',\n", + " \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\",\n", + " 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains',\n", + " 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022',\n", + " 'England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics',\n", + " \"There is a concerning trend of treating living beings, particularly popular 'designer' dog breeds, as commodities rather than sentient beings\",\n", + " \"The cultural shift in Britain towards treating pets as substitutes for children, favoring aesthetics over the animal's natural function and well-being\",\n", + " 'Consumerism in pet care is escalating in the UK with a significant increase in unnecessary spending on pets, including trends and luxury items',\n", + " 'Pets are often indulged with unnecessary treats and services that do not align with their genuine needs or desires, indicative of human emotional solace through consumption',\n", + " 'Modern lifestyles with busy schedules are causing dogs to live monotonous lives, leading to behavioral problems that are often placated by trivial indulgences',\n", + " \"Proper pet care advocates for prioritizing pets' quality of life and well-being over anthropomorphic indulgences and misguided expressions of affection\",\n", + " \"Kate Fox, an anthropologist who described Britons' affection towards pets as a way of life in her book 'Watching the English'\",\n", + " 'Dogs serve as an outlet for emotions and social engagement for Britons',\n", + " 'In the UK, dogs are accepted and encouraged in various public spaces like transport, pubs, and shops',\n", + " 'Despite societal changes, the passion for animals in the UK has been consistent',\n", + " 'The COVID-19 pandemic led to a surge in pet ownership, increasing the number of dogs in the UK',\n", + " \"'A dog is for life, not just for Christmas' is a slogan by Dogs Trust charity to advocate responsible pet ownership\",\n", + " 'The number of dog attacks in England and Wales saw a significant rise',\n", + " \"Certain dog breeds are increasingly perceived as commodities, particularly 'designer' breeds\",\n", + " 'Consumer spending on pets in the UK has increased, extending to non-essential items and services',\n", + " 'Many dogs experience lack of socialization and extended periods of isolation due to modern human schedules',\n", + " 'Ensuring the well-being of pets should be a priority, demanding sacrifices and quality care from the owners',\n", + " 'Britons have a significant and emotional connection with animals, particularly dogs.',\n", + " 'Kate Fox, an anthropologist who wrote about the English way of life with pets.',\n", + " 'Number of pet dogs in the UK increased from about nine million to 13 million between 2019 and 2022.',\n", + " 'In the UK, dogs are often encouraged to accompany their owners in public places such as pubs and shops.',\n", + " 'The number of dog attacks recorded by police in England and Wales rose by more than a third between 2018 and 2022.',\n", + " 'Pets, particularly dogs, are increasingly being treated as commodities rather than sentient beings.',\n", + " 'Popularity of designer breeds like French bulldogs and pugs, which often suffer due to their physical features.',\n", + " 'Controversial American XL bully dogs are sought after as a signifier of masculinity.',\n", + " 'Pets are increasingly being treated as substitutes for children, altering the traditional British perspective of valuing dogs for their natural qualities.',\n", + " 'Spending on pets in the UK has more than doubled in the past decade, reaching nearly £10bn in the previous year.',\n", + " 'Rise in dog-friendly establishments like restaurants, theaters, and even churches, catering to dog owners more than the dogs themselves.',\n", + " \"Many dogs suffer from daily deprivation and lack engagement due to their owner's busy schedules.\",\n", + " 'Behavioral issues in dogs often stem from insufficient exercise, supervision, and consistent routines.'],\n", + " ['In British culture, keeping pets is an integral way of life and an outlet for emotions, with a particular fondness for dogs',\n", + " 'Dogs serve as an acceptable outlet for typically controlled British emotions, facilitating affection and sociability',\n", + " \"Public spaces in the UK are accommodating of dogs, with signs such as 'Dogs welcome, people tolerated' and treats offered in establishments\",\n", + " 'Dogs act as social catalysts, making it more acceptable to converse with strangers in parks rather than more formal settings like trains',\n", + " 'The COVID-19 pandemic caused a surge in pet ownership in the UK, with the dog population rising from 9 million to 13 million between 2019 and 2022',\n", + " 'England and Wales saw a significant increase in dog attacks between 2018 and 2022, aligning with a rise in the number of dogs and changes in ownership dynamics',\n", + " \"There is a concerning trend of treating living beings, particularly popular 'designer' dog breeds, as commodities rather than sentient beings\",\n", + " \"The cultural shift in Britain towards treating pets as substitutes for children, favoring aesthetics over the animal's natural function and well-being\",\n", + " 'Consumerism in pet care is escalating in the UK with a significant increase in unnecessary spending on pets, including trends and luxury items',\n", + " 'Pets are often indulged with unnecessary treats and services that do not align with their genuine needs or desires, indicative of human emotional solace through consumption',\n", + " 'Modern lifestyles with busy schedules are causing dogs to live monotonous lives, leading to behavioral problems that are often placated by trivial indulgences',\n", + " \"Proper pet care advocates for prioritizing pets' quality of life and well-being over anthropomorphic indulgences and misguided expressions of affection\",\n", + " \"Kate Fox, an anthropologist who described Britons' affection towards pets as a way of life in her book 'Watching the English'\",\n", + " 'Dogs serve as an outlet for emotions and social engagement for Britons',\n", + " 'In the UK, dogs are accepted and encouraged in various public spaces like transport, pubs, and shops',\n", + " 'Despite societal changes, the passion for animals in the UK has been consistent',\n", + " 'The COVID-19 pandemic led to a surge in pet ownership, increasing the number of dogs in the UK',\n", + " \"'A dog is for life, not just for Christmas' is a slogan by Dogs Trust charity to advocate responsible pet ownership\",\n", + " 'The number of dog attacks in England and Wales saw a significant rise',\n", + " \"Certain dog breeds are increasingly perceived as commodities, particularly 'designer' breeds\",\n", + " 'Consumer spending on pets in the UK has increased, extending to non-essential items and services',\n", + " 'Many dogs experience lack of socialization and extended periods of isolation due to modern human schedules',\n", + " 'Ensuring the well-being of pets should be a priority, demanding sacrifices and quality care from the owners',\n", + " 'Britons have a significant and emotional connection with animals, particularly dogs.',\n", + " 'Kate Fox, an anthropologist who wrote about the English way of life with pets.',\n", + " 'Number of pet dogs in the UK increased from about nine million to 13 million between 2019 and 2022.',\n", + " 'In the UK, dogs are often encouraged to accompany their owners in public places such as pubs and shops.',\n", + " 'The number of dog attacks recorded by police in England and Wales rose by more than a third between 2018 and 2022.',\n", + " 'Pets, particularly dogs, are increasingly being treated as commodities rather than sentient beings.',\n", + " 'Popularity of designer breeds like French bulldogs and pugs, which often suffer due to their physical features.',\n", + " 'Controversial American XL bully dogs are sought after as a signifier of masculinity.',\n", + " 'Pets are increasingly being treated as substitutes for children, altering the traditional British perspective of valuing dogs for their natural qualities.',\n", + " 'Spending on pets in the UK has more than doubled in the past decade, reaching nearly £10bn in the previous year.',\n", + " 'Rise in dog-friendly establishments like restaurants, theaters, and even churches, catering to dog owners more than the dogs themselves.',\n", + " \"Many dogs suffer from daily deprivation and lack engagement due to their owner's busy schedules.\",\n", + " 'Behavioral issues in dogs often stem from insufficient exercise, supervision, and consistent routines.']]" + ] + }, + "execution_count": 516, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "context" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "217fcdd1-e1f7-48f3-a835-cfd003bd6da9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f974c87e-4117-4f93-a96c-e4fcd741aed9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c9b14de-85f1-4aec-ab80-54e4b2a8f317", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, "id": "eebe4f53-c6ba-466a-8ba2-adee16fb6e21", "metadata": {}, "outputs": [], - "source": [ - "def get_nodes_with_high_weight_edges(graph, weight_threshold=0.9):\n", - " \"\"\"\n", - " Fetch nodes in the graph that are connected by edges with a weight higher than the specified threshold.\n", - "\n", - " :param graph: A NetworkX graph object.\n", - " :param weight_threshold: The minimum weight threshold for edges to consider (default is 0.9).\n", - " :return: A set of nodes that are connected by edges with weight greater than the specified threshold.\n", - " \"\"\"\n", - " nodes_set = set()\n", - "\n", - " # Iterate over all edges in the graph\n", - " for u, v, data in graph.edges(data=True):\n", - " # Check if the edge weight is greater than the threshold\n", - " if data.get('weight', 0) > weight_threshold:\n", - " # If so, add both nodes connected by this edge to the set\n", - " nodes_set.add(u)\n", - " nodes_set.add(v)\n", - "\n", - " return nodes_set" - ] + "source": [] }, { "cell_type": "code", @@ -4579,50 +4954,23 @@ "id": "cca2637a-eace-4763-ada4-0ce925afd7ce", "metadata": {}, "outputs": [], - "source": [ - "target_node_id = 'Natural Language Text:Personal narratives and stories'\n", - "\n", - "# Use the neighbors() function to get all nodes connected to the target node\n", - "connected_nodes = list(CONNECTED_GRAPH.neighbors(target_node_id))" - ] + "source": [] }, { "cell_type": "code", - "execution_count": 401, + "execution_count": null, "id": "e67c6679-f339-4ad1-b1bc-0c896a973abe", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Lee Parkin, 50, owner of the late terrier-spaniel cross Izzy, suffers from PTSD - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 493b9555-a150-4b2f-9dbc-0b3f699f7249', 'Izzy, a terrier-spaniel cross owned by Lee Parkin, killed by an XL bully - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 646af2be-f8ac-45f3-beba-b3ce21bfa019', 'An XL bully attacked and killed Izzy during a walk with Lee Parkin in Doncaster - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 3774e1cd-3728-419b-a2a7-7b89c4522366', 'Doncaster, the location where Izzy was attacked and killed by an XL bully - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 967f6c80-01f0-4a96-860d-cff5cdc4a5bc', \"Naevia, Marie Hay's Siberian husky, survived an attack by two XL bullies with life-changing injuries - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - c72d5b7c-67be-43b8-b3e8-feccd8ba4a7d\", 'Marie Hay, owner of Naevia, who survived an XL bully attack with mental and physical scars - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 996ac877-2ddd-45c3-b7ba-7aba6bcd0f81', 'Two XL bullies attacked Naevia on a beach in Redcar, causing severe injuries - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 5bd9aee2-5f56-45ef-abee-b952e013f772', 'Redcar Beach on the North Yorkshire coast, where Naevia was attacked by two XL bullies - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 18209f5f-6965-4029-97d0-8f0a6e4121c2', 'XL bully, a breed involved in attacks on Izzy and Naevia, seen as dangerously out of control - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 4f8a3746-3c0d-4e3f-badb-55f89270aa05', 'An incoming ban on XL bullies supported by Lee Parkin and Marie Hay but with reservations on its effectiveness - 269f0df8-8091-442c-9392-0b710e4dc350 - 27a76d52-5b5e-4e8e-8726-29be55c8b2f1 - 2f4d11f2-6e19-4ec6-a655-7a3ed7d9329a', 'Lee Parkin - 50-year-old dog owner, suffers from post-traumatic stress disorder after his dog was killed. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - 1b71310b-7bae-4f7a-953e-756cce8f880f', 'Izzy - Terrier-spaniel cross, pet dog owned by Lee Parkin for nearly 10 years, killed in dog attack. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - 69dea689-2e52-4c6c-ab25-2621ef27c6d3', 'Doncaster - The location near where Lee Parkin was walking his dog Izzy when she was attacked. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - a9cb9715-8f25-45cd-beca-71ea3afcb28c', 'XL Bully - Breed of dog that attacked and killed Izzy, described as dangerously out of control. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - 3bd1d070-b76c-4bc4-948c-0cb8f608e49e', 'Marie Hay - Dog owner whose Siberian Husky, Naevia, survived an attack but suffered life-changing injuries. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - 0fc6079d-5b2c-4d90-8e05-69a5a5109d7c', 'Naevia - Siberian Husky owned by Marie Hay, survived a savage attack by two XL Bullies. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - 5a6df745-7ecd-4ac9-8f6a-5f1dc547a9ac', 'Redcar Beach on the North Yorkshire coast - The location where Naevia was attacked by two XL Bullies. - 269f0df8-8091-442c-9392-0b710e4dc350 - c306c248-bbab-44a9-9ae2-448f992e415c - e39ec471-29bf-4581-8542-b358300312a4', 'Lee Parkin, a 50-year-old man and owner of the dog Izzy. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - 606800f1-fc9f-43a5-997c-4966b0b77fe8', 'Izzy, a terrier-spaniel cross owned by Lee Parkin for nearly 10 years. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - e44e53b3-120f-4f63-b20f-a60bb24c3ef2', 'Attack by an XL bully on Izzy resulting in her death. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - 855a05eb-c5ca-434e-a25c-534a608b2568', 'Lee Parkin was diagnosed with post-traumatic stress disorder after the attack. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - 6513305f-ca46-4708-b869-6688fa6552c5', 'Marie Hay, owner of seven-year-old Siberian husky Naevia, also victim of an XL bully attack. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - b2a03c68-609a-4839-a85f-b586be5d2e8f', 'Naevia, a seven-year-old Siberian husky owned by Marie Hay, survived an attack by two XL bullies with life-changing injuries. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - 9d464c7c-16ff-4081-b630-f3288519ccfc', 'The incoming ban on XL bullies that both Lee Parkin and Marie Hay support. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - 61d8f944-8c52-4ee3-8252-a5ae2c898d12', 'Anxiety and fear faced by Lee Parkin and Marie Hay when walking dogs post-attack. - 269f0df8-8091-442c-9392-0b710e4dc350 - dbcbc6c6-db82-48f3-8fa9-e3d372ff3483 - f8cccf2f-0b34-4dd3-92b0-8ac8a34c5c0a']\n" - ] - } - ], - "source": [ - "print(connected_nodes)" - ] + "outputs": [], + "source": [] }, { "cell_type": "code", - "execution_count": 213, + "execution_count": null, "id": "418ef758-64e1-4c44-a844-9e3960d9db50", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Nodes in the graph: ['user123', 'Temporal', 'Temporal:Historical events', 'Temporal:Schedules and timelines', 'Positional', 'Positional:Geographical locations', 'Positional:Spatial data', 'Propositions', 'Propositions:Hypotheses and theories', 'Propositions:Claims and arguments', 'Personalization', 'Personalization:User preferences', 'Personalization:User information', 'Natural Language Text', 'Natural Language Text:News stories and blog posts']\n" - ] - } - ], - "source": [ - "nodes = list(G.nodes())\n", - "\n", - "print(\"Nodes in the graph:\", nodes)" - ] + "outputs": [], + "source": [] }, { "cell_type": "code",