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