-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from biothings/semmed-sentences
semmed sentence edge attributes
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters