Skip to content

Commit

Permalink
feat: allow transform to plural type
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoshuBaby committed Feb 29, 2024
1 parent c5e23fe commit 4741907
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
10 changes: 4 additions & 6 deletions src/yuheng/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,12 @@ def have_multi_elements(element_id_string: str) -> bool:
)
)
+ "/"
+ (
prefix_normalization(element_type, mode="p2prefix")
+ "s"
+ prefix_normalization(
element_type, mode="p2prefix", plural=True
)
+ "?"
+ (
prefix_normalization(element_type, mode="p2prefix")
+ "s"
+ prefix_normalization(
element_type, mode="p2prefix", plural=True
)
+ "="
+ ",".join(pure_id_list)
Expand Down
37 changes: 26 additions & 11 deletions src/yuheng/method/transform.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
from typing import Optional


def prefix_normalization(source: str, mode="p2prefix") -> str:
def prefix_normalization(source: str, mode="p2prefix", plural=False) -> str:
if mode == "p2prefix":
if source == "n" or source == "node":
return "node"
if plural == False:
return "node"
else:
return "nodes"
if source == "w" or source == "way":
return "way"
if plural == False:
return "way"
else:
return "ways"
if source == "r" or source == "relation":
return "relation"
if plural == False:
return "relation"
else:
return "relations"
if source == "c" or source == "changeset":
return "changeset"
if plural == False:
return "changeset"
else:
return "changesets"
if source == "v" or source == "version":
return "version"
if plural == False:
return "version"
else:
return "versions"
elif mode == "prefix2p":
if source == "n" or source == "node":
if source in ["n", "node", "nodes"]:
return "n"
if source == "w" or source == "way":
if source in ["w", "way", "nodes"]:
return "w"
if source == "r" or source == "relation":
if source in ["r", "relation", "relations"]:
return "r"
if source == "c" or source == "changeset":
if source in ["c", "changeset", "changesets"]:
return "c"
if source == "v" or source == "version":
if source in ["v", "version", "versions"]:
return "v"


Expand Down

0 comments on commit 4741907

Please sign in to comment.