MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / computeSynthRelation

Function computeSynthRelation

union/Santos/query.py:84–145  ·  view source on GitHub ↗
(inputTable, subjectIndex, synthKB)

Source from the content-addressed store, hash-verified

82
83#compute synthesized relationship semantics for the query table
84def computeSynthRelation(inputTable, subjectIndex, synthKB):
85 label = "r"
86 relationSemantics = {}
87 synth_triple_dict = {}
88 total_cols = inputTable.shape[1]
89 subject_semantics = set()
90 for i in range(0, total_cols -1):
91 if genFunc.getColumnType(inputTable.iloc[:,i].tolist()) == 1: #the subject in rdf triple should be a text column
92 for j in range(i+1, total_cols):
93 if genFunc.getColumnType(inputTable.iloc[:,j].tolist()) == 1: #the subject in rdf triple should be a text column
94 mergeRelSem = {}
95 dataFrameTemp = inputTable.iloc[:,[i,j]]
96 dataFrameTemp = (dataFrameTemp.drop_duplicates()).dropna()
97 projectedRowsNum = dataFrameTemp.shape[0]
98
99 #find relation semantics for each value pairs of subjectIndex and j
100 for k in range(0,projectedRowsNum):
101 #extract subject and object
102 sub = genFunc.preprocessString(str(dataFrameTemp.iloc[k][0]).lower())
103 obj = genFunc.preprocessString(str(dataFrameTemp.iloc[k][1]).lower())
104 subNull = genFunc.checkIfNullString(sub)
105 objNull = genFunc.checkIfNullString(obj)
106 if subNull != 0 and objNull != 0:
107 item = []
108 value = sub+"__"+obj
109 if value in synthKB:
110 item = synthKB[value]
111
112 else:
113 value = obj+"__"+sub
114 if value in synthKB:
115 item = synthKB[value]
116
117 if len(item) > 0 :
118 for each in item:
119 temp = each
120 if temp[-1] >0:
121 semName = temp[0]
122 semScore = temp[-1]
123 if semName in mergeRelSem:
124 mergeRelSem[semName] +=semScore/projectedRowsNum
125 else:
126 mergeRelSem[semName] = semScore/projectedRowsNum
127
128
129 triple_list = []
130 for sem in mergeRelSem:
131 triple_list.append((sem, mergeRelSem[sem]))
132
133 synth_triple_dict[str(i) + "-" + str(j)] = triple_list
134 if int(subjectIndex) == i or int(subjectIndex) == j:
135 for sem in mergeRelSem:
136 subject_semantics.add(sem)
137 for sem in mergeRelSem:
138 if sem in relationSemantics:
139 currentList = relationSemantics[sem]
140 currentScore = currentList[0]
141 newScore = currentScore + mergeRelSem[sem]

Callers 1

query.pyFile · 0.70

Calls 1

addMethod · 0.45

Tested by

no test coverage detected