public class InferenceEngine extends Object
The inference engine collects evidence from various sources in the SQL statement and uses it to infer which columns belong to which tables. This is particularly useful when: - Database metadata is not available - Dealing with SELECT * without schema information - Analyzing SQL from unknown sources
Inference process: 1. Collect evidence from SQL statement (WHERE, JOIN, SELECT, etc.) 2. Aggregate evidence by table and column 3. Calculate confidence scores 4. Generate inferred column sources
Example:
SELECT * FROM employees e WHERE e.department_id = 10 AND e.salary > 50000 Inference: - "department_id" column exists in "employees" (confidence: 0.95) - "salary" column exists in "employees" (confidence: 0.95)
| Constructor and Description |
|---|
InferenceEngine() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAllEvidence(Collection<InferenceEvidence> evidences)
Add multiple pieces of evidence.
|
void |
addEvidence(InferenceEvidence evidence)
Add a piece of evidence for inference.
|
double |
calculateConfidence(String tableName,
String columnName)
Calculate the combined confidence for a table.column based on all evidence.
|
void |
clear()
Clear all evidence and inferred columns.
|
ColumnSource |
createInferredColumnSource(String tableName,
String columnName,
TTable table)
Create an inferred ColumnSource for a table.column.
|
List<InferenceEvidence> |
getEvidence(String tableName,
String columnName)
Get all evidence for a specific table.column.
|
int |
getEvidenceCount()
Get total number of pieces of evidence collected.
|
int |
getInferredColumnCount()
Get total number of inferred columns across all tables.
|
Set<String> |
getInferredColumns(String tableName)
Get all inferred columns for a table.
|
String |
getStatistics()
Get statistics about the inference engine state.
|
Set<String> |
getTablesWithInferences()
Get all tables that have inferred columns.
|
String |
toString() |
public InferenceEngine()
public void addEvidence(InferenceEvidence evidence)
evidence - the evidence to addpublic void addAllEvidence(Collection<InferenceEvidence> evidences)
evidences - the evidence to addpublic Set<String> getInferredColumns(String tableName)
tableName - the table namepublic List<InferenceEvidence> getEvidence(String tableName, String columnName)
tableName - the table namecolumnName - the column namepublic double calculateConfidence(String tableName, String columnName)
Combines multiple pieces of evidence using formula:
combined = 1 - ∏(1 - conf_i)This means: - Multiple pieces of evidence increase confidence - Evidence is independent (multiplicative combination) - Result is always in [0, 1]
tableName - the table namecolumnName - the column namepublic ColumnSource createInferredColumnSource(String tableName, String columnName, TTable table)
tableName - the table namecolumnName - the column nametable - the TTable object (may be null if not available)public Set<String> getTablesWithInferences()
public int getEvidenceCount()
public int getInferredColumnCount()
public void clear()
public String getStatistics()