Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
alphabetization in recursion #4
Browse files Browse the repository at this point in the history
  • Loading branch information
turbomam committed Jan 19, 2022
1 parent b03314a commit 8cbfb33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
16 changes: 11 additions & 5 deletions hident/hident.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,18 @@ def requesteds_from_txt_file(self, textfile_name: str, colnum=0, header=None):
logger.debug(requesteds)
self.requesteds = list(requesteds)

def alphabetize_requesteds(self):
def alphabetize_terms(self, term_list) -> list:
lf = self.label_frame
rts = self.requesteds
lf = lf.loc[lf['class'].isin(rts)]
lf = lf.loc[lf['class'].isin(term_list)]
lf = lf.sort_values(by='label')
self.requesteds = list(lf['class'])
logger.info(lf)
alphabetized = list(lf['class'])
# logger.info(lf)
return alphabetized

def alphabetize_requesteds(self):
term_list = self.requesteds
alphabetized = self.alphabetize_terms(term_list)
self.requesteds = alphabetized

def prepare_frame(self, frame_file_name: str, cols_to_tidy: list[str], header=1, sep="\t") -> pd.DataFrame:
# assuming they're full IRIs (but without < or >
Expand Down Expand Up @@ -175,6 +180,7 @@ def indent_from_term(self, term_id: str, indent_level: int):
indented_lab = padding + term_lab
self.append_id_lab(term_id, indented_lab)
subs = term_dict['subs']
subs = self.alphabetize_terms(subs)
for i in subs:
new_indent_level = indent_level + 1
self.indent_from_term(i, new_indent_level)
Expand Down
20 changes: 10 additions & 10 deletions target/soils_indented.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ id indented_lab
ENVO:01001835 alpine biome
ENVO:01001505 alpine tundra biome
ENVO:01000219 anthropogenic terrestrial biome
ENVO:01000246 village biome
ENVO:01000247 rangeland biome
ENVO:01000246 village biome
ENVO:01001838 arid biome
ENVO:01000181 mangrove biome
ENVO:01001836 montane biome
Expand All @@ -12,16 +12,16 @@ ENVO:01000216 montane shrubland biome
ENVO:01000339 polar biome
ENVO:01000176 shrubland biome
ENVO:01000216 montane shrubland biome
ENVO:01000215 temperate shrubland biome
ENVO:01000214 tropical shrubland biome
ENVO:01000213 subtropical shrubland biome
ENVO:01000217 mediterranean shrubland biome
ENVO:01000215 temperate shrubland biome
ENVO:01000214 tropical shrubland biome
ENVO:01001837 subalpine biome
ENVO:01001834 subpolar biome
ENVO:01001832 subtropical biome
ENVO:01001833 mediterranean biome
ENVO:01000217 mediterranean shrubland biome
ENVO:01000229 mediterranean savanna biome
ENVO:01000217 mediterranean shrubland biome
ENVO:01000208 mediterranean woodland biome
ENVO:01000187 subtropical savanna biome
ENVO:01000229 mediterranean savanna biome
Expand All @@ -31,24 +31,24 @@ ENVO:01000222 subtropical woodland biome
ENVO:01000208 mediterranean woodland biome
ENVO:01001831 temperate biome
ENVO:01000189 temperate savanna biome
ENVO:01000221 temperate woodland biome
ENVO:01000215 temperate shrubland biome
ENVO:01000221 temperate woodland biome
ENVO:01001830 tropical biome
ENVO:01000220 tropical woodland biome
ENVO:01000188 tropical savanna biome
ENVO:01000214 tropical shrubland biome
ENVO:01000220 tropical woodland biome
ENVO:01000180 tundra biome
ENVO:01001505 alpine tundra biome
ENVO:01000249 urban biome
ENVO:01000175 woodland biome
ENVO:01000222 subtropical woodland biome
ENVO:01000208 mediterranean woodland biome
ENVO:01000178 savanna biome
ENVO:01000190 flooded savanna biome
ENVO:01000189 temperate savanna biome
ENVO:01000188 tropical savanna biome
ENVO:01000223 montane savanna biome
ENVO:01000187 subtropical savanna biome
ENVO:01000229 mediterranean savanna biome
ENVO:01000189 temperate savanna biome
ENVO:01000188 tropical savanna biome
ENVO:01000222 subtropical woodland biome
ENVO:01000208 mediterranean woodland biome
ENVO:01000221 temperate woodland biome
ENVO:01000220 tropical woodland biome

0 comments on commit 8cbfb33

Please sign in to comment.