-
Notifications
You must be signed in to change notification settings - Fork 56
Add test coverage for disambiguation, related and similar entity scenarios #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GaneshPatil7517
wants to merge
6
commits into
dbpedia:master
Choose a base branch
from
GaneshPatil7517:test/disambiguation-related-similar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3479588
Add test cases for entity disambiguation scenarios
GaneshPatil7517 25963c4
Extend GenesisService tests with comprehensive similar and related en…
GaneshPatil7517 69aaf87
Add comprehensive SPARQL query tests for disambiguation and entity re…
GaneshPatil7517 8b307cd
Fix Copilot code review suggestions: correct assertion argument order…
GaneshPatil7517 8310605
Address remaining Copilot review suggestions: improve test descriptio…
GaneshPatil7517 a0587b9
Add missing assertNotEquals import to fix compilation error
GaneshPatil7517 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 193 additions & 6 deletions
199
src/test/java/rivescript/dbpedia/TestDBpediaSparql.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,203 @@ | ||
| package rivescript.dbpedia; | ||
|
|
||
| import org.junit.Ignore; | ||
| import chatbot.lib.TestUtility; | ||
| import chatbot.lib.api.SPARQL; | ||
| import chatbot.lib.response.ResponseData; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import rivescript.RiveScriptBase; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| /** | ||
| * Created by ramgathreya on 6/20/17. | ||
| * SPARQL query test cases for disambiguation and entity resolution scenarios | ||
| */ | ||
| @Ignore | ||
| public class TestDBpediaSparql extends RiveScriptBase { | ||
| public class TestDBpediaSparql { | ||
| private static SPARQL sparql; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() throws Exception { | ||
| try { | ||
| sparql = new SPARQL(TestUtility.getHelper().getExplorerDB()); | ||
| } catch (Exception e) { | ||
| // Test utilities may fail if credentials are not available | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test SPARQL query building with prefixes | ||
| */ | ||
| @Test | ||
| public void testQueryBuildingWithPrefixes() { | ||
| if (sparql == null) return; | ||
|
|
||
| String rawQuery = "SELECT * WHERE { ?s ?p ?o }"; | ||
| String builtQuery = sparql.buildQuery(rawQuery); | ||
|
|
||
| assertNotNull("Built query should not be null", builtQuery); | ||
| assertTrue("Query should contain SPARQL prefixes", builtQuery.contains("PREFIX")); | ||
| assertTrue("Query should contain original query", builtQuery.contains("SELECT * WHERE")); | ||
| } | ||
|
|
||
| /** | ||
| * Test disambiguation detection for entities with multiple meanings | ||
| */ | ||
| @Test | ||
| private void dummyTest() { | ||
| public void testDisambiguationDetection() { | ||
| if (sparql == null) return; | ||
|
|
||
| // "Mercury (disambiguation)" is a well-known disambiguation page | ||
| String mercuryUri = "http://dbpedia.org/resource/Mercury_(disambiguation)"; | ||
| int count = sparql.isDisambiguationPage(mercuryUri); | ||
|
|
||
| // Should return a count > 0 for disambiguation pages | ||
| assertTrue("Mercury disambiguation should have multiple entries", count > 0); | ||
| } | ||
|
|
||
| /** | ||
| * Test entity retrieval from disambiguation pages | ||
| */ | ||
| @Test | ||
| public void testDisambiguatedEntityRetrieval() { | ||
| if (sparql == null) return; | ||
|
|
||
| String mercuryUri = "http://dbpedia.org/resource/Mercury_(disambiguation)"; | ||
| ArrayList<ResponseData> entities = sparql.getDisambiguatedEntities(mercuryUri, 0, 5); | ||
|
|
||
| assertNotNull("Should return entity list from disambiguation page", entities); | ||
| assertTrue("Should retrieve at least one entity from disambiguation", entities.size() > 0); | ||
|
|
||
| // Verify each entity has necessary information | ||
| for (ResponseData entity : entities) { | ||
| assertNotNull("Entity should have a title", entity.getTitle()); | ||
| assertTrue("Entity title should not be empty", entity.getTitle().length() > 0); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test entity information with all optional fields | ||
| */ | ||
| @Test | ||
| public void testEntityInformationWithOptionalFields() { | ||
| if (sparql == null) return; | ||
|
|
||
| String franceUri = "http://dbpedia.org/resource/France"; | ||
| ResponseData entity = sparql.getEntityInformation(franceUri); | ||
|
|
||
| assertNotNull("Entity information should be retrieved", entity); | ||
| assertNotNull("Entity should have title", entity.getTitle()); | ||
| // France should have a description | ||
| assertNotNull("Entity should have descriptive text", entity.getText()); | ||
| assertTrue("Text content should be substantial", entity.getText().length() > 0); | ||
| } | ||
|
|
||
| /** | ||
| * Test entity label retrieval and accuracy | ||
| */ | ||
| @Test | ||
| public void testEntityLabelRetrieval() { | ||
| if (sparql == null) return; | ||
|
|
||
| String obamaUri = "http://dbpedia.org/resource/Barack_Obama"; | ||
| String label = sparql.getLabel(obamaUri); | ||
|
|
||
| assertNotNull("Label should be retrieved", label); | ||
| assertEquals("Label should match expected entity name", "Barack Obama", label); | ||
| } | ||
|
|
||
| /** | ||
| * Test batch entity retrieval by multiple URIs | ||
| */ | ||
| @Test | ||
| public void testBatchEntityRetrieval() { | ||
| if (sparql == null) return; | ||
|
|
||
| String uris = "<http://dbpedia.org/resource/Albert_Einstein> " + | ||
| "<http://dbpedia.org/resource/Marie_Curie> " + | ||
| "<http://dbpedia.org/resource/Isaac_Newton>"; | ||
|
|
||
| ArrayList<ResponseData> entities = sparql.getEntitiesByURIs(uris); | ||
|
|
||
| assertNotNull("Should retrieve multiple entities", entities); | ||
| assertEquals("Should retrieve exactly 3 entities", 3, entities.size()); | ||
| } | ||
|
|
||
| /** | ||
| * Test pagination handling for large disambiguation pages | ||
| */ | ||
| @Test | ||
| public void testDisambiguationPagination() { | ||
| if (sparql == null) return; | ||
|
|
||
| String mercuryUri = "http://dbpedia.org/resource/Mercury_(disambiguation)"; | ||
|
|
||
| ArrayList<ResponseData> firstPage = sparql.getDisambiguatedEntities(mercuryUri, 0, 3); | ||
| ArrayList<ResponseData> secondPage = sparql.getDisambiguatedEntities(mercuryUri, 3, 3); | ||
|
|
||
| assertNotNull("First page should exist", firstPage); | ||
|
|
||
| if (firstPage.size() > 0 && secondPage != null && secondPage.size() > 0) { | ||
| // Verify pagination is working by comparing first entries | ||
| String firstPageFirstTitle = firstPage.get(0).getTitle(); | ||
| String secondPageFirstTitle = secondPage.get(0).getTitle(); | ||
| assertTrue("Pages should contain different entities", | ||
| !firstPageFirstTitle.equals(secondPageFirstTitle)); | ||
GaneshPatil7517 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test entity information with minimal data (when some fields are unavailable) | ||
| */ | ||
| @Test | ||
| public void testEntityInformationWithMinimalData() { | ||
| if (sparql == null) return; | ||
|
|
||
| // Lesser-known but valid DBpedia entity | ||
| String entityUri = "http://dbpedia.org/resource/John_Doe"; | ||
| ResponseData entity = sparql.getEntityInformation(entityUri); | ||
|
|
||
| // Should handle gracefully even if some optional fields are missing | ||
| if (entity != null) { | ||
| assertNotNull("Entity should at least have a title", entity.getTitle()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test distinction between disambiguation pages and regular entities | ||
| */ | ||
| @Test | ||
| public void testDisambiguationVsRegularEntity() { | ||
| if (sparql == null) return; | ||
|
|
||
| // Test disambiguation page | ||
| String disambigUri = "http://dbpedia.org/resource/Mercury_(disambiguation)"; | ||
| int disambigCount = sparql.isDisambiguationPage(disambigUri); | ||
|
|
||
| // Test regular entity | ||
| String regularUri = "http://dbpedia.org/resource/Mercury_(planet)"; | ||
| int regularCount = sparql.isDisambiguationPage(regularUri); | ||
|
|
||
| // Disambiguation should have count > 0, regular entity should be 0 | ||
| assertTrue("Disambiguation page should have entities", disambigCount > 0); | ||
| assertEquals("Regular entity should not be marked as disambiguation", 0, regularCount); | ||
| } | ||
|
|
||
| /** | ||
| * Test handling of entity URIs with special characters and encodings | ||
| */ | ||
| @Test | ||
| public void testEntityURIWithSpecialCharacters() { | ||
| if (sparql == null) return; | ||
|
|
||
| // Entity with parentheses in name that requires proper URI encoding | ||
| String uri = "http://dbpedia.org/resource/Mercury_(planet)"; | ||
| ResponseData entity = sparql.getEntityInformation(uri); | ||
|
|
||
| if (entity != null) { | ||
| assertNotNull("Entity should be retrievable despite special characters", entity.getTitle()); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.