Skip to content

Instantly share code, notes, and snippets.

@myedibleenso
Created September 9, 2016 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myedibleenso/8383af789b37ba598ff64ddd12c8b35b to your computer and use it in GitHub Desktop.
Save myedibleenso/8383af789b37ba598ff64ddd12c8b35b to your computer and use it in GitHub Desktop.
{
"documents":{
"350376968":{
"id":"",
"text":"Phosphorylated MEK activates K-RAS.",
"sentences":[{
"words":["Phosphorylated","MEK","activates","K-RAS","."],
"startOffsets":[0,15,19,29,34],
"endOffsets":[14,18,28,34,35],
"tags":["VBN","NN","VBZ","NN","."],
"lemmas":["phosphorylate","mek","activate","k-ra","."],
"entities":["O","B-Family","O","B-Gene_or_gene_product","O"],
"chunks":["B-NP","I-NP","B-VP","B-NP","O"],
"graphs":{
"stanford-basic":{
"edges":[{
"source":0,
"destination":1,
"relation":"dobj"
},{
"source":2,
"destination":0,
"relation":"csubj"
},{
"source":2,
"destination":3,
"relation":"dobj"
}],
"roots":[2]
},
"stanford-collapsed":{
"edges":[{
"source":0,
"destination":1,
"relation":"dobj"
},{
"source":2,
"destination":0,
"relation":"csubj"
},{
"source":2,
"destination":3,
"relation":"dobj"
}],
"roots":[2]
}
}
}]
}
},
"mentions":[{
"type":"CorefTextBoundMention",
"id":"T:-1519180061",
"text":"MEK",
"labels":["Family","Equivalable","BioChemicalEntity","BioEntity","Entity","PossibleController"],
"tokenInterval":{
"start":1,
"end":2
},
"characterStartOffset":15,
"characterEndOffset":18,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"ner-family-entities",
"modifications":[{
"modification-type":"PTM",
"label":"Phosphorylation",
"evidence":{
"type":"CorefTextBoundMention",
"id":"T:396586846",
"text":"Phosphorylated",
"labels":["ModificationTrigger"],
"tokenInterval":{
"start":0,
"end":1
},
"characterStartOffset":0,
"characterEndOffset":14,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"modification_trigger_1",
"grounding":{
"text":"Phosphorylated",
"key":"phosphorylated",
"namespace":"uaz",
"id":"UAZ00001",
"species":""
},
"displayLabel":"ModificationTrigger"
},
"negated":false
}],
"grounding":{
"text":"MEK",
"key":"mek",
"namespace":"uaz",
"id":"UAZ-PF-132",
"species":"human"
},
"displayLabel":"Family"
},{
"type":"CorefTextBoundMention",
"id":"T:-2037729273",
"text":"K-RAS",
"labels":["Gene_or_gene_product","MacroMolecule","Equivalable","BioChemicalEntity","BioEntity","Entity","PossibleController"],
"tokenInterval":{
"start":3,
"end":4
},
"characterStartOffset":29,
"characterEndOffset":34,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"ner-gene_or_gene_product-entities",
"grounding":{
"text":"KRAS",
"key":"kras",
"namespace":"uniprot",
"id":"P01116",
"species":"human"
},
"displayLabel":"Protein"
},{
"type":"CorefEventMention",
"id":"E:38453071",
"text":"MEK activates K-RAS",
"labels":["Positive_activation","ActivationEvent","ComplexEvent","Event","PossibleController"],
"trigger":{
"type":"CorefTextBoundMention",
"id":"T:786232869",
"text":"activates",
"labels":["Positive_activation","ActivationEvent","ComplexEvent","Event","PossibleController"],
"tokenInterval":{
"start":2,
"end":3
},
"characterStartOffset":19,
"characterEndOffset":28,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"Positive_activation_token_1_verb",
"displayLabel":"Positive_activation"
},
"arguments":{
"controller":[{
"type":"CorefTextBoundMention",
"id":"T:-1519180061",
"text":"MEK",
"labels":["Family","Equivalable","BioChemicalEntity","BioEntity","Entity","PossibleController"],
"tokenInterval":{
"start":1,
"end":2
},
"characterStartOffset":15,
"characterEndOffset":18,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"ner-family-entities",
"modifications":[{
"modification-type":"PTM",
"label":"Phosphorylation",
"evidence":{
"type":"CorefTextBoundMention",
"id":"T:396586846",
"text":"Phosphorylated",
"labels":["ModificationTrigger"],
"tokenInterval":{
"start":0,
"end":1
},
"characterStartOffset":0,
"characterEndOffset":14,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"modification_trigger_1",
"grounding":{
"text":"Phosphorylated",
"key":"phosphorylated",
"namespace":"uaz",
"id":"UAZ00001",
"species":""
},
"displayLabel":"ModificationTrigger"
},
"negated":false
}],
"grounding":{
"text":"MEK",
"key":"mek",
"namespace":"uaz",
"id":"UAZ-PF-132",
"species":"human"
},
"displayLabel":"Family"
}],
"controlled":[{
"type":"CorefTextBoundMention",
"id":"T:-2037729273",
"text":"K-RAS",
"labels":["Gene_or_gene_product","MacroMolecule","Equivalable","BioChemicalEntity","BioEntity","Entity","PossibleController"],
"tokenInterval":{
"start":3,
"end":4
},
"characterStartOffset":29,
"characterEndOffset":34,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"ner-gene_or_gene_product-entities",
"grounding":{
"text":"KRAS",
"key":"kras",
"namespace":"uniprot",
"id":"P01116",
"species":"human"
},
"displayLabel":"Protein"
}]
},
"tokenInterval":{
"start":1,
"end":4
},
"characterStartOffset":15,
"characterEndOffset":34,
"sentence":0,
"document":"350376968",
"keep":true,
"foundBy":"Positive_activation_token_1_verb",
"displayLabel":"Positive_activation",
"isDirect":false
}]
}
import org.clulab.reach.PaperReader
import org.clulab.reach.mentions._
import org.clulab.reach.serialization.json._
import java.io.File
/** Example demonstrating how to serialize/deserialize
* [[org.clulab.reach.mentions.CorefMention]] to/from json
*/
object ReachJSONExample extends App {
val text = "Phosphorylated MEK activates K-RAS."
// extract mentions and covert each to CorefMention
val corefmentions: Seq[CorefMention] = PaperReader.getMentionsFromText(text).map(_.toCorefMention)
// print the json string for the extracted mentions
println(corefmentions.json(pretty=true))
// save the json to a file
corefmentions.saveJSON("corefmentions.json", pretty = true)
// deserialize the mentions json that was written in the last step
val corefmentions2 = JSONSerializer.toCorefMentions(new File("corefmentions.json"))
// demonstrate that the json of the deserialized mentions is equivalent to the original Seq[CorefMention]
corefmentions.json(pretty = true) == corefmentions2.json(pretty = true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment