graphQL
1.0.0
스크립트에서 R#
패키지를 가져온 다음 빈 그래프 데이터베이스를 만듭니다.
import graphQL
kb = MsgFile :: open ()
그런 다음 지식 데이터를 데이터베이스 엔진에 삽입할 수 있습니다.
# example of insert the knowledge data in table format liked:
# key value
# ---------------------------------------------------
# <mode> <string> <string>
# [1, ] "id" "C01405"
# [2, ] "name" "Aspirin"
# [3, ] "name" "Acetylsalicylic acid"
# [4, ] "name" "2-Acetoxybenzenecarboxylic acid"
# [5, ] "name" "Acetylsalicylate"
# [6, ] "formula" "C9H8O4"
# [ reached 'max' / getOption("max.print") -- omitted 7 rows ]
def process_knowledge ( kb , data ):
data = as . list ( data , byrow = True )
data = groupBy ( data , x - > x [[ "key" ]])
data = lapply ( data , x - > sapply ( x , i - > i [[ "value" ]]), x - > x [[ "key" ]])
Query :: insert ( kb , data [[ "id" ]], data )
마침내 쿼리 기능을 사용하여 지식 데이터베이스를 쿼리하거나 두 용어가 동일한지 여부를 확인할 수 있습니까?
# query knowledge data by term
result = Query :: query ( kb , "Aspirin" )
# [1] "Aspirin is the name of C01405 with confidence 1.00"
# [2] "Aspirin is the name of HMDB0001879 with confidence 1.00"
# [3] "Aspirin is the name of ChEBI:15365 with confidence 1.00"
# assert that two term are identical or not?
Query :: similarity ( kb , "Aspirin" , "Acetylsalicylic acid" )
# [1] 0.740741
Query :: similarity ( kb , "Aspirin" , "water" )
# [1] 0
Query :: similarity ( kb , "dihydrogen oxide" , "water" )
# [1] 0.35