Skip to content

add --format tsv option to gen-prefix-map generator#451

Merged
cmungall merged 5 commits intomainfrom
spatil/genprefixmap-add-option
Nov 5, 2021
Merged

add --format tsv option to gen-prefix-map generator#451
cmungall merged 5 commits intomainfrom
spatil/genprefixmap-add-option

Conversation

@sujaypatil96
Copy link
Copy Markdown
Member

Per my understanding of issue #447, I have added support to prefixmapgen.py as in this following PR.

Execute the following command to see it in action:

gen-prefix-map examples/PersonSchema/personinfo.yaml --format tsv

See the sample output from the above command below:

CODE    http://example.org/code/
GEO     http://example.org/geoloc/
GSSO    http://purl.obolibrary.org/obo/GSSO_
P       http://example.org/P/
ROR     http://example.org/ror/
famrel  https://example.org/FamilialRelations#
linkml  https://w3id.org/linkml/
personinfo      https://w3id.org/linkml/examples/personinfo/
prov    http://www.w3.org/ns/prov#
rdf     http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs    http://www.w3.org/2000/01/rdf-schema#
schema  http://schema.org/
skos    http://example.org/UNKNOWN/skos/
xsd     http://www.w3.org/2001/XMLSchema#

You can also redirect the tsv output into a .tsv file in the following way:

gen-prefix-map examples/PersonSchema/personinfo.yaml --format tsv > examples/personinfo.tsv

CC: @cmungall

@cmungall
Copy link
Copy Markdown
Member

cmungall commented Nov 3, 2021

can you also add a test?

@sujaypatil96
Copy link
Copy Markdown
Member Author

sujaypatil96 commented Nov 3, 2021

@cmungall: yes, I'll add a test as well.

Also I realized that prefixmapgen.py didn't have support to redirect output using the --output option, so I added it in the above commit.

@sujaypatil96 sujaypatil96 force-pushed the spatil/genprefixmap-add-option branch from 0c4e3b9 to 39b3bad Compare November 3, 2021 21:24
@sujaypatil96
Copy link
Copy Markdown
Member Author

I'm not sure how we would write a test for this @cmungall?

Since the value of --format is being captured in end_schema() rather than in the PrefixGenerator.__init__() constructor, there's no way we can invoke that particular use case in the test_prefixgen() test case here?

@sujaypatil96 sujaypatil96 marked this pull request as ready for review November 3, 2021 22:25
@sujaypatil96 sujaypatil96 linked an issue Nov 3, 2021 that may be closed by this pull request
@sujaypatil96 sujaypatil96 added this to the 2021-12-01 milestone Nov 3, 2021
@sujaypatil96 sujaypatil96 added enhancement New feature or request formatting labels Nov 3, 2021
@sujaypatil96 sujaypatil96 requested a review from cmungall November 3, 2021 22:46
@cmungall
Copy link
Copy Markdown
Member

cmungall commented Nov 3, 2021

there must be a way to pass in format as an argument - either in the constructor, or in the serialize method?

@sujaypatil96
Copy link
Copy Markdown
Member Author

sujaypatil96 commented Nov 4, 2021

@cmungall: I've added a test for the new --format tsv option for genprefixmap.py in test_prefixes.py.

@sujaypatil96 sujaypatil96 requested a review from cmungall November 4, 2021 23:46
@sujaypatil96
Copy link
Copy Markdown
Member Author

Looks like all the checks went through Chris, this PR is probably ready to be merged.

if output:
with open(output, 'w') as outf:
outf.write(as_json(context))
output_ext = output.split(".")[-1]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably warn if this over-rides the users explicit choice

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, so this isn't necessarily overriding anything. It just parses out the file extension from the filename that is supplied via the --output option.

mapping[prefix] = self.namespaces[prefix]

for key, value in mapping.items():
print(key, value, sep='\t')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, it's just a 2 column tsv so this is OK - but why not use this same simple form when writing to a file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to use csv.writer() to make sure the data is being correctly formatted and written to a tsv file rather than stringing the key and value together with a \t separator.

@cmungall cmungall merged commit eb7f74d into main Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tsv option for gen-prefix-map

2 participants