Skip to content

Commit

Permalink
Merge pull request #68 from biothings/semmed-sentences
Browse files Browse the repository at this point in the history
semmed sentence edge attributes
  • Loading branch information
tokebe authored Sep 27, 2024
2 parents d24c07a + 4020739 commit 38811c0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
23 changes: 23 additions & 0 deletions data/jq/pair/semmed.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if $edge.query.method == "post" then
# if response is not an array, then use response.hits
if (.response | type) == "array" then .response else .response.hits end |
reduce .[] as $item ({};
# if the item is notfound, then proceed to next item & keep current object
if ($item | keys | contains(["notfound"])) then
.
else
generateCurieWithInputs(
$edge.input.id;
$item.query;
$edge.input.curies
| toArray
| map(. | split(":") | last)
) as $curie | .[$curie] += [$item]
end
)
else
.response as $res | generateCurie(
$edge.input.id;
($edge.input.curies | toArray | map(. | split(":") | last) | first)
) as $curie | {} | .[$curie] = [$res]
end
29 changes: 29 additions & 0 deletions data/jq/wrap/semmed.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# finds start/end index of sub in main string
# ie. "ab" in "12abcd" will return "2|3"
def index_text(main; sub): (main|index(sub)|tostring)+"|"+((main|index(sub)) + (sub|length) | tostring);


.["edge-attributes"] = ([.predication | group_by(.pmid) | .[] | .[0] |
# create edge attributes for each publication
{
"attribute_type_id": "biolink:has_supporting_study_result",
"attributes": [
{
"attribute_type_id": "biolink:supporting_text",
"value": .sentence,
},
{
"attribute_type_id": "biolink:publications",
"value": ( "PMID:"+(.pmid|tostring) ),
},
{
"attribute_type_id": "biolink:subject_location_in_text",
"value": ( .subject_text as $text | index_text(.sentence; $text) ),
},
{
"attribute_type_id": "biolink:object_location_in_text",
"value": ( .object_text as $text | index_text(.sentence; $text) ),
}
],
"value": ( .predication_id | tostring ),
}] | .[:50])
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default class Transformer {
} else if (api === "EBI Proteins API") {
// this.tf = new EBIProteinTransformer(this.data, this.config)
this.tf = new JQTransformer(this.data, { ...this.config, type: "ebi" });
} else if (api === "BioThings SEMMEDDB API") {
this.tf = new JQTransformer(this.data, { ...this.config, type: "semmed" });
} else if (tags.includes("biothings")) {
this.tf = new JQTransformer(this.data, { ...this.config, type: "biothings" });
} else if (tags.includes("ctd")) {
Expand Down

0 comments on commit 38811c0

Please sign in to comment.