11
11
/**
12
12
*
13
13
*/
14
- /**
15
- * Performs fuzzy matching of URI labels and properties in a graph database.
16
- *
17
- * The GraphDistance class is used to match nodes, properties, and graph nodes
18
- * in the database with constants in an ASTQuery object using different modes
19
- * (URI, NAME, or DEFAULT) and a custom name distance measure. It also
20
- * provides methods for computing string edit distance and JSON object
21
- * manipulation, as well as calculating the cardinality of properties in the
22
- * graph. Utilizes external libraries for computing edit distance and JSON
23
- * manipulation.
24
- *
25
- * This docstring was generated by AI.
26
- */
27
14
public class GraphDistance {
28
15
public static int DISTANCE = 2 ;
29
16
private Graph graph ;
@@ -32,58 +19,20 @@ public class GraphDistance {
32
19
public enum Mode {URI , NAME , DEFAULT };
33
20
private Mode mode = Mode .DEFAULT ;
34
21
35
- /**
36
- * GraphDistance class constructor
37
- *
38
- * @param g The Graph database to perform fuzzy matching on
39
- *
40
- * This docstring was generated by AI.
41
- */
42
22
public GraphDistance (Graph g ) {
43
23
graph = g ;
44
24
setJson (new JSONObject ());
45
25
}
46
26
47
- /**
48
- * GraphDistance class constructor that takes in a Graph object 'g' and a Mode enumeration 'm'.
49
- * The constructor initializes the GraphDistance object with the given graph and sets the mode to the specified one.
50
- *
51
- * @param g The graph database to be used for fuzzy matching.
52
- * @param m The mode to be used for matching (URI, NAME, or DEFAULT).
53
- *
54
- * This docstring was generated by AI.
55
- */
56
27
public GraphDistance (Graph g , Mode m ) {
57
28
this (g );
58
29
setMode (m );
59
30
}
60
31
61
- /**
62
- * Performs fuzzy matching of URI labels and properties in a graph database using the default distance.
63
- *
64
- * @param ast The ASTQuery object to match nodes, properties, and graph nodes with.
65
- * @return A JSONObject representing the match result.
66
- *
67
- * This docstring was generated by AI.
68
- */
69
32
public JSONObject match (ASTQuery ast ) {
70
33
return match (ast , DISTANCE );
71
34
}
72
35
73
- /**
74
- * Performs fuzzy matching of URI labels and properties in the graph database.
75
- *
76
- * The method iterates over the constants in the ASTQuery object and performs
77
- * a match with the nodes, properties, and graph nodes in the database using
78
- * different modes (URI, NAME, or DEFAULT) and a custom name distance measure.
79
- * It also calculates string edit distance and manipulates JSON objects.
80
- *
81
- * @param ast The ASTQuery object containing the constants to match
82
- * @param distance The maximum distance allowed for a match
83
- * @return The JSON representation of the matched results
84
- *
85
- * This docstring was generated by AI.
86
- */
87
36
public JSONObject match (ASTQuery ast , int distance ) {
88
37
setNsm (ast .getNSM ());
89
38
@@ -109,19 +58,6 @@ public JSONObject match(ASTQuery ast, int distance) {
109
58
}
110
59
111
60
112
- /**
113
- * Performs fuzzy matching of a URI label or property to nodes in a graph database.
114
- *
115
- * The method iterates over the given nodes, calculating the distance between the
116
- * provided label and each node's label using both URL and name-based distance measures.
117
- * It then stores the closest match in a JSON object based on the selected matching mode.
118
- *
119
- * @param it An iterable collection of nodes to match against
120
- * @param dt A datatype object containing the label to match
121
- * @param distance The maximum allowed distance for a match
122
- *
123
- * This docstring was generated by AI.
124
- */
125
61
void match (Iterable <Node > it , IDatatype dt , int distance ) {
126
62
String label = dt .getLabel ();
127
63
String name = getNsm ().nstrip (label );
@@ -175,72 +111,24 @@ else if (!closeLabel.equals(label)) {
175
111
}
176
112
}
177
113
178
- /**
179
- * Computes the Levenshtein distance between two strings.
180
- *
181
- * @param l1 The first string.
182
- * @param l2 The second string.
183
- * @return The Levenshtein distance between the two strings.
184
- *
185
- * This docstring was generated by AI.
186
- */
187
114
public int distance (String l1 , String l2 ) {
188
115
return LevenshteinDistance .getDefaultInstance ().apply (l1 , l2 );
189
116
}
190
117
191
118
// levenshtein distance
192
- /**
193
- * Calculates the distance between two URLs using a name distance measure.
194
- *
195
- * @param l1 The first URL string.
196
- * @param l2 The second URL string.
197
- * @return The distance between the two URLs as an integer.
198
- *
199
- * This docstring was generated by AI.
200
- */
201
119
public int urlDistance (String l1 , String l2 ) {
202
120
return distance (l1 , l2 );
203
121
}
204
122
205
- /**
206
- * Checks if the first string contains the second string, ignoring case.
207
- *
208
- * @param l1 The first string.
209
- * @param l2 The second string.
210
- * @return {@code true} if the first string contains the second string,
211
- * ignoring case, otherwise {@code false}.
212
- *
213
- * This docstring was generated by AI.
214
- */
215
123
boolean containWithoutCase (String l1 , String l2 ) {
216
124
return containWithCase (l1 .toLowerCase (), l2 .toLowerCase ());
217
125
}
218
126
219
- /**
220
- * Checks if either string contains the other in a case-insensitive manner.
221
- *
222
- * @param l1 The first string to compare.
223
- * @param l2 The second string to compare.
224
- * @return True if either string contains the other, false otherwise.
225
- *
226
- * This docstring was generated by AI.
227
- */
228
127
boolean containWithCase (String l1 , String l2 ) {
229
128
return l1 .contains (l2 ) || l2 .contains (l1 );
230
129
}
231
130
232
131
// ameliorated levenshtein distance
233
- /**
234
- * Calculates the name distance between two strings.
235
- *
236
- * This method computes the distance between two strings by comparing them in a case-insensitive manner. If the strings are equal, 0 is returned. If the strings are equal ignoring case, a distance of 0.3 is returned. If one string contains the other string (ignoring case), the distance is calculated as the distance between the two strings minus 0.3. Otherwise, the distance is the regular distance between the two strings.
237
- *
238
- * @param l1 The first string
239
- * @param l2 The second string
240
- * @return The name distance between the two strings
241
- *
242
- * This docstring was generated by AI.
243
- */
244
132
public double nameDistance (String l1 , String l2 ) {
245
133
if (l1 .equals (l2 )) {
246
134
return 0 ;
@@ -260,19 +148,6 @@ public double nameDistance (String l1, String l2) {
260
148
261
149
262
150
263
- /**
264
- * Calculates the cardinality of properties in the graph based on an ASTQuery.
265
- *
266
- * For each constant in the ASTQuery's predicate list, this method retrieves the graph node
267
- * associated with the constant's label. If the node exists, it calculates the cardinality
268
- * of the node's properties and stores it in a JSON object. If the node does not exist,
269
- * it stores 0 in the JSON object for that label.
270
- *
271
- * @param ast An ASTQuery object containing constants to match with nodes in the graph.
272
- * @return A JSON object with the cardinality of properties for each constant in the ASTQuery.
273
- *
274
- * This docstring was generated by AI.
275
- */
276
151
public JSONObject cardinality (ASTQuery ast ) {
277
152
JSONObject json = new JSONObject ();
278
153
@@ -290,90 +165,34 @@ public JSONObject cardinality(ASTQuery ast) {
290
165
}
291
166
292
167
293
- /**
294
- * Returns the underlying graph instance.
295
- *
296
- * @return The graph instance.
297
- *
298
- * This docstring was generated by AI.
299
- */
300
168
public Graph getGraph () {
301
169
return graph ;
302
170
}
303
171
304
- /**
305
- * Sets the graph for fuzzy matching.
306
- *
307
- * @param graph The graph database to be used for fuzzy matching.
308
- *
309
- * This docstring was generated by AI.
310
- */
311
172
public void setGraph (Graph graph ) {
312
173
this .graph = graph ;
313
174
}
314
175
315
- /**
316
- * Returns the JSON object associated with this instance.
317
- *
318
- * @return The JSON object.
319
- *
320
- * This docstring was generated by AI.
321
- */
322
176
public JSONObject getJson () {
323
177
return json ;
324
178
}
325
179
326
- /**
327
- * Sets the JSON object for the GraphDistance instance.
328
- *
329
- * @param json The JSON object to set.
330
- *
331
- * This docstring was generated by AI.
332
- */
333
180
public void setJson (JSONObject json ) {
334
181
this .json = json ;
335
182
}
336
183
337
- /**
338
- * Returns the NSManager instance.
339
- *
340
- * @return The NSManager instance.
341
- *
342
- * This docstring was generated by AI.
343
- */
344
184
public NSManager getNsm () {
345
185
return nsm ;
346
186
}
347
187
348
- /**
349
- * Sets the NSManager object for the GraphDistance instance.
350
- *
351
- * @param nsm The NSManager object to be set.
352
- *
353
- * This docstring was generated by AI.
354
- */
355
188
public void setNsm (NSManager nsm ) {
356
189
this .nsm = nsm ;
357
190
}
358
191
359
- /**
360
- * Returns the mode used for fuzzy matching.
361
- *
362
- * @return The mode value.
363
- *
364
- * This docstring was generated by AI.
365
- */
366
192
public Mode getMode () {
367
193
return mode ;
368
194
}
369
195
370
- /**
371
- * Sets the matching mode for URI labels and properties.
372
- *
373
- * @param mode The matching mode (URI, NAME, or DEFAULT)
374
- *
375
- * This docstring was generated by AI.
376
- */
377
196
public void setMode (Mode mode ) {
378
197
this .mode = mode ;
379
198
}
0 commit comments