Skip to content

Commit 11505af

Browse files
committed
Revert "feat: wip on:"
This reverts commit b5bcefc.
1 parent b5bcefc commit 11505af

File tree

8 files changed

+31
-89
lines changed

8 files changed

+31
-89
lines changed

.github/workflows/github-projects-for-openfoodfacts-design.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ jobs:
5959
project-url: https://github.com/orgs/openfoodfacts/projects/5 # Add issue to the folksonomy project
6060
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
6161
labeled: 🏷️ Folksonomy Project
62-
label-operator: OR
62+
label-operator: OR
6363
- uses: actions/add-to-project@main
6464
with:
6565
project-url: https://github.com/orgs/openfoodfacts/projects/44 # Add issue to the data quality project
6666
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
6767
labeled: 🧽 Data quality
68-
label-operator: OR
68+
label-operator: OR
6969
- uses: actions/add-to-project@main
7070
with:
7171
project-url: https://github.com/orgs/openfoodfacts/projects/82 # Add issue to the search project
@@ -77,19 +77,19 @@ jobs:
7777
project-url: https://github.com/orgs/openfoodfacts/projects/41 # Add issue to the producer platform project
7878
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
7979
labeled: 🏭 Producers Platform
80-
label-operator: OR
80+
label-operator: OR
8181
- uses: actions/add-to-project@main
8282
with:
8383
project-url: https://github.com/orgs/openfoodfacts/projects/19 # Add issue to the infrastructure project
8484
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
8585
labeled: infrastructure
86-
label-operator: OR
86+
label-operator: OR
8787
- uses: actions/add-to-project@main
8888
with:
8989
project-url: https://github.com/orgs/openfoodfacts/projects/92 # Add issue to the Nutri-Score project
9090
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
9191
labeled: 🚦 Nutri-Score
92-
label-operator: OR
92+
label-operator: OR
9393
- uses: actions/add-to-project@main
9494
with:
9595
project-url: https://github.com/orgs/openfoodfacts/projects/132 # Add issue to the Top upvoted issues board
@@ -107,4 +107,4 @@ jobs:
107107
project-url: https://github.com/orgs/openfoodfacts/projects/35 # Add issue to the ♿️ accessibility project
108108
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
109109
labeled: ♿️ accessibility
110-
label-operator: OR
110+
label-operator: OR

backend/editor/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def find_all_nodes(response: Response, branch: str, taxonomy_name: str):
184184
Get all nodes within taxonomy
185185
"""
186186
taxonomy = TaxonomyGraph(branch, taxonomy_name)
187-
all_nodes = await taxonomy.get_all_nodes()
187+
all_nodes = await taxonomy.get_all_nodes("")
188188
return all_nodes
189189

190190

backend/editor/controllers/node_controller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async def create_entry_node(
3838
"id": language_code + ":" + normalized_name,
3939
f"tags_{language_code}": [name],
4040
f"tags_ids_{language_code}": [normalized_name],
41-
f"modified": datetime.datetime.now().timestamp(),
4241
}
4342
params = {"entry_node": entry_node_data}
4443

backend/editor/entries.py

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ async def list_projects(self, status=None):
342342

343343
async def add_node_to_end(self, label, entry):
344344
"""
345-
Helper function which adds an a newly created node to end of taxonomy
345+
Helper function which adds an existing node to end of taxonomy
346346
"""
347347
# Delete relationship between current last node and __footer__
348348
query = f"""
@@ -394,37 +394,28 @@ async def add_node_to_beginning(self, label, entry):
394394
async def delete_node(self, label, entry):
395395
"""
396396
Helper function used for deleting a node with given id and label
397-
398-
We don't really delete it because we have to keep track of modified nodes.
399-
We set the entry type lable to REMOVED_<label>
400397
"""
401-
# Remove node from is_before relation and attach node previous node to next node
398+
# Finding node to be deleted using node ID
402399
query = f"""
403400
// Find node to be deleted using node ID
404401
MATCH (deleted_node:{self.project_name}:{label})-[:is_before]->(next_node)
405402
WHERE deleted_node.id = $id
406403
MATCH (previous_node)-[:is_before]->(deleted_node)
407404
// Remove node
408-
DETACH (deleted_node)
405+
DETACH DELETE (deleted_node)
409406
// Rebuild relationships after deletion
410407
CREATE (previous_node)-[:is_before]->(next_node)
411408
"""
412-
# change label of node to be deleted
413-
query = f"""
414-
MATCH (deleted_node:{self.project_name}:{label}) WHERE deleted_node.id = $id
415-
REMOVE deleted_node:{label}
416-
SET deleted_node:REMOVED_{label}
417-
"""
418409
result = await get_current_transaction().run(query, {"id": entry})
419410
return await async_list(result)
420411

421412
async def get_all_nodes(self, label):
422413
"""
423414
Helper function used for getting all nodes with/without given label
424415
"""
425-
qualifier = f"{label}" if label else "|".join(label.value for label in NodeType)
416+
qualifier = f":{label}" if label else ""
426417
query = f"""
427-
MATCH (n:{self.project_name}:{qualifier}) RETURN n
418+
MATCH (n:{self.project_name}{qualifier}) RETURN n
428419
"""
429420
result = await get_current_transaction().run(query)
430421
return await async_list(result)
@@ -531,9 +522,6 @@ async def update_node(self, label, new_node: EntryNode):
531522
# Build query
532523
query = [f"""MATCH (n:{self.project_name}:{label}) WHERE n.id = $id """]
533524

534-
modified = datetime.datetime.now().timestamp()
535-
query.append(f"""\nSET n.modified * ${modified}""")
536-
537525
# Delete keys removed by user
538526
deleted_keys = (
539527
(set(curr_node.tags.keys()) - set(new_node.tags.keys()))
@@ -570,33 +558,24 @@ async def update_node_children(self, entry, new_children_ids):
570558
"""
571559
Helper function used for updation of node children with given id
572560
"""
573-
modified = datetime.datetime.now().timestamp()
574561
# Parse node ids from Neo4j Record object
575562
current_children = [record["child.id"] for record in list(await self.get_children(entry))]
576563
deleted_children = set(current_children) - set(new_children_ids)
577564
added_children = set(new_children_ids) - set(current_children)
578565

579566
# Delete relationships
580-
query = f"""
581-
MATCH
582-
(deleted_child:{self.project_name}:ENTRY)
583-
-[rel:is_child_of]->
584-
(parent:{self.project_name}:ENTRY)
585-
WHERE parent.id = $id AND deleted_child.id IN $children
586-
DELETE rel
587-
"""
588-
await get_current_transaction().run(query, {"id": entry, "children": deleted_children})
589-
# update children modified property
590-
query = f"""
591-
MATCH (child:{self.project_name}:ENTRY)
592-
WHERE child.id in $children
593-
SET child.modified = $modified
594-
"""
595-
await get_current_transaction().run(
596-
query, {"children": deleted_children, "modified": modified}
597-
)
567+
for child in deleted_children:
568+
query = f"""
569+
MATCH
570+
(deleted_child:{self.project_name}:ENTRY)
571+
-[rel:is_child_of]->
572+
(parent:{self.project_name}:ENTRY)
573+
WHERE parent.id = $id AND deleted_child.id = $child
574+
DELETE rel
575+
"""
576+
await get_current_transaction().run(query, {"id": entry, "child": child})
598577

599-
# get non-existing nodes
578+
# Create non-existing nodes
600579
query = f"""
601580
MATCH (child:{self.project_name}:ENTRY)
602581
WHERE child.id in $ids RETURN child.id
@@ -607,7 +586,7 @@ async def update_node_children(self, entry, new_children_ids):
607586

608587
# Normalising new children node ID
609588
created_child_ids = []
610-
# create new nodes
589+
611590
for child in to_create:
612591
main_language_code, child_name = child.split(":", 1)
613592
created_node_id = await self.create_entry_node(child_name, main_language_code)
@@ -633,13 +612,5 @@ async def update_node_children(self, entry, new_children_ids):
633612
query, {"id": entry, "child_id": child_id}
634613
)
635614
result = list(await _result.value())
636-
# update modified of existing but added children entries
637-
# update children modified property
638-
query = f"""
639-
MATCH (child:{self.project_name}:ENTRY)
640-
WHERE child.id in $children
641-
SET child.modified = $modified
642-
"""
643-
await get_current_transaction().run(query, {"children": existing_ids, "modified": modified})
644615

645616
return result

parser/openfoodfacts_taxonomy_parser/parser/parser.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def _create_other_node(self, tx: Transaction, node_data: NodeData, project_label
3434
base_properties_query = """
3535
id: $id,
3636
preceding_lines: $preceding_lines,
37-
src_position: $src_position,
38-
src_lines: $src_lines
37+
src_position: $src_position
3938
"""
4039

4140
properties_query = ",\n".join([base_properties_query, *node_tags_queries])
@@ -229,8 +228,7 @@ def _create_node_indexes(self, project_label: str):
229228

230229
self.parser_logger.info(f"Created indexes in {timeit.default_timer() - start_time} seconds")
231230

232-
def _write_nodes_to_db(self, taxonomy: Taxonomy, taxonomy_name: str, branch_name: str):
233-
"""Create the taxonomy objects in the database: nodes and link between them"""
231+
def _write_to_database(self, taxonomy: Taxonomy, taxonomy_name: str, branch_name: str):
234232
project_label = get_project_name(taxonomy_name, branch_name)
235233
# First create nodes,
236234
# then create node indexes to accelerate relationship creation,
@@ -241,16 +239,6 @@ def _write_nodes_to_db(self, taxonomy: Taxonomy, taxonomy_name: str, branch_name
241239
self._create_child_links(taxonomy.child_links, project_label)
242240
self._create_previous_links(taxonomy.previous_links, project_label)
243241

244-
def _add_text_to_project(self, filename: str, taxonomy_name: str, branch_name: str):
245-
"""Add file content to the db"""
246-
project_label = get_project_name(taxonomy_name, branch_name)
247-
query = f"""
248-
MATCH (n:{project_label})
249-
SET n.original_text = $original_text
250-
"""
251-
params = {"original_text": open(filename, "r", encoding="utf-8").read()}
252-
self.session.run(query, params)
253-
254242
def __call__(
255243
self,
256244
main_filename: str,
@@ -268,9 +256,8 @@ def __call__(
268256
taxonomy = taxonomy_parser.parse_file(
269257
main_filename, external_filenames, self.parser_logger
270258
)
271-
# add file content to the db
272-
self._add_text_to_project(main_filename, taxonomy_name, branch_name)
273-
self._write_nodes_to_db(taxonomy, taxonomy_name, branch_name)
259+
260+
self._write_to_database(taxonomy, taxonomy_name, branch_name)
274261

275262
self.parser_logger.info(
276263
f"Finished parsing {taxonomy_name} in {timeit.default_timer() - start_time} seconds"

parser/openfoodfacts_taxonomy_parser/parser/taxonomy_parser.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class NodeData:
2727
preceding_lines: list[str] = field(default_factory=list)
2828
parent_tags: list[tuple[str, int]] = field(default_factory=list)
2929
src_position: int | None = None
30-
# lines taken by this entry in the source file
31-
# this can be more than (start, end) if we merged duplicates
32-
src_lines: list[tuple[int, int]] | None = None
3330
properties: dict[str, str] = field(default_factory=dict)
3431
tags: dict[str, list[str]] = field(default_factory=dict)
3532
comments: dict[str, list[str]] = field(default_factory=dict)
@@ -42,7 +39,6 @@ def to_dict(self):
4239
"main_language": self.main_language,
4340
"preceding_lines": self.preceding_lines,
4441
"src_position": self.src_position,
45-
"src_lines": self.src_lines,
4642
"is_external": self.is_external,
4743
"original_taxonomy": self.original_taxonomy,
4844
**self.properties,
@@ -234,9 +230,8 @@ def is_entry_synonyms_line(self, line):
234230
)
235231
return False
236232

237-
def finalize_data(self, data, comments, saved_nodes, line_number: int):
233+
def finalize_data(self, data, comments, saved_nodes):
238234
data = self._remove_separating_line(data)
239-
data.src_lines = [(data.src_position, line_number)]
240235
if data.get_node_type() == NodeType.ENTRY:
241236
self._add_comments(data, comments, "end")
242237
if data.id in saved_nodes:
@@ -381,7 +376,7 @@ def _harvest_entries(self, filename: str, entries_start_line: int) -> Iterator[N
381376
# another function will use data to create a node
382377
if previous_data is not None:
383378
yield previous_data # it's ok with this one
384-
previous_data = self.finalize_data(data, comments, saved_nodes, line_number)
379+
previous_data = self.finalize_data(data, comments, saved_nodes)
385380
# if data was a duplicate (is_before is None) reuse same is_before
386381
is_before = data.id if data.is_before else is_before
387382
data = NodeData(is_before=is_before)
@@ -567,8 +562,6 @@ def _merge_duplicate_entry_nodes(self, entry_nodes: list[NodeData]) -> list[Node
567562
)
568563
# union of the preceding_lines comments
569564
first_node.preceding_lines.extend(node.preceding_lines)
570-
# union of src_lines
571-
first_node.src_lines.extend(node.src_lines)
572565
else:
573566
unique_entry_nodes.append(node)
574567
ids_to_nodes[node.id] = node
@@ -594,12 +587,7 @@ def _create_taxonomy(
594587
entry_nodes: list[NodeData] = []
595588
entry_nodes.extend(external_entry_nodes)
596589
other_nodes = [
597-
NodeData(
598-
id="__header__",
599-
preceding_lines=harvested_header_data,
600-
src_position=1,
601-
src_lines=[(1, entries_start_line - 1)],
602-
)
590+
NodeData(id="__header__", preceding_lines=harvested_header_data, src_position=1)
603591
]
604592
previous_links: list[PreviousLink] = []
605593
raw_child_links: list[ChildLink] = []

parser/openfoodfacts_taxonomy_parser/patcher.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

parser/openfoodfacts_taxonomy_parser/unparser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""This module takes a taxonomy from a Neo4j database and write it down as a text file"""
2-
31
import os
42
import sys
53

0 commit comments

Comments
 (0)