Difference between revisions of "Annotator R Client"
Jump to navigation
Jump to search
(→Example: minor tweaks for clarity) |
|||
(One intermediate revision by the same user not shown) | |||
Line 7: | Line 7: | ||
# | # | ||
− | |||
− | + | annotate.it <- function( queryText, yourAPIKey ) { | |
− | |||
− | |||
− | |||
− | |||
− | annotate.it <- function( queryText ) { | ||
library(RCurl) | library(RCurl) | ||
Line 22: | Line 16: | ||
res<- postForm('http://rest.bioontology.org/obs/annotator', | res<- postForm('http://rest.bioontology.org/obs/annotator', | ||
"textToAnnotate"=queryText, | "textToAnnotate"=queryText, | ||
− | "apikey"= | + | "apikey"=yourAPIKey, |
"style"="POST", | "style"="POST", | ||
"longestOnly"="false", | "longestOnly"="false", | ||
Line 64: | Line 58: | ||
resultNodes <- getNodeSet(x, "/success/data/annotatorResultBean/annotations/annotationBean/context") | resultNodes <- getNodeSet(x, "/success/data/annotatorResultBean/annotations/annotationBean/context") | ||
for( result in resultNodes ) { | for( result in resultNodes ) { | ||
− | localConceptId <- xmlValue(getNodeSet(result,"./term/localConceptId")[[1]]) | + | localConceptId <- xmlValue(getNodeSet(result,"./term/concept/localConceptId")[[1]]) |
print( paste( "ID = ", localConceptId ) ) | print( paste( "ID = ", localConceptId ) ) | ||
Line 83: | Line 77: | ||
} | } | ||
} | } | ||
+ | |||
+ | queryText <- "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye" | ||
+ | |||
+ | # Instructions on getting an API key are at http://www.bioontology.org/wiki/index.php/Annotator_User_Guide#Annotator_Web_service_Validation | ||
+ | yourAPIKey <- "XXXXXXXXXXXXX" | ||
+ | |||
+ | annotate.it( queryText, yourAPIKey ) | ||
</pre> | </pre> |
Latest revision as of 09:41, 19 December 2013
Example
# # sample client for NCBO Annotator in R # Author: Andrew Su # annotate.it <- function( queryText, yourAPIKey ) { library(RCurl) library(XML) # Login to BioPortal to get YourAPIKey res<- postForm('http://rest.bioontology.org/obs/annotator', "textToAnnotate"=queryText, "apikey"=yourAPIKey, "style"="POST", "longestOnly"="false", "wholeWordOnly"="true", "filterNumber"="true", "withDefaultStopWords"="true", "isStopWordsCaseSensitive"="false", "minTermSize"="3", "scored"="true", "withSynonyms"="true", "ontologiesToExpand"="1353,1032,1351,1009", "ontologiesToKeepInResult"="1353,1032,1351,1009", "isVirtualOntologyId"="true", "semanticTypes"="T017,T047,T191,T999", "levelMax"="0", "mappingTypes"="null", "format"="xml", "email"="YourEmail@Somewhere.com") x <- xmlInternalTreeParse(res) matchedConcepts <- list() conceptNodes <- getNodeSet(x,"/success/data/annotatorResultBean/annotations/annotationBean/concept") for( concept in conceptNodes ) { localConceptId <- xmlValue(getNodeSet(concept,"./localConceptId")[[1]]) print( paste( "ID = ",localConceptId )) preferredName <- xmlValue(getNodeSet(concept,"./preferredName")[[1]]) print( paste( "Name = ",preferredName )) semanticType <- xmlValue(getNodeSet(concept,"./semanticTypes/semanticTypeBean/semanticType")[[1]]) print( paste( "Type = ",semanticType )) description <- xmlValue(getNodeSet(concept,"./semanticTypes/semanticTypeBean/description")[[1]]) print( paste( "Type name = ",description )) matchedConcepts[[localConceptId]] <- preferredName } matchedPhrase <- list() resultNodes <- getNodeSet(x, "/success/data/annotatorResultBean/annotations/annotationBean/context") for( result in resultNodes ) { localConceptId <- xmlValue(getNodeSet(result,"./term/concept/localConceptId")[[1]]) print( paste( "ID = ", localConceptId ) ) term.name <- xmlValue(getNodeSet(result,"./term/name")[[1]]) print( paste( "Match = ", term.name ) ) from <- xmlValue(getNodeSet(result,"./from")[[1]]) print( paste( "From = ", from ) ) to <- xmlValue(getNodeSet(result,"./to")[[1]]) print( paste( "To = ", to ) ) matchedPhrase[[localConceptId]] <- term.name } for( key in names(matchedConcepts) ) { print(paste(key,matchedConcepts[[key]],"matched",matchedPhrase[[key]])) } } queryText <- "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye" # Instructions on getting an API key are at http://www.bioontology.org/wiki/index.php/Annotator_User_Guide#Annotator_Web_service_Validation yourAPIKey <- "XXXXXXXXXXXXX" annotate.it( queryText, yourAPIKey )