Skip to content

Commit

Permalink
Merge pull request #6 from aleksandr-isaev/master
Browse files Browse the repository at this point in the history
Various bug fixes and new script to count total number of links for each algorithm
  • Loading branch information
aldearle authored Sep 27, 2024
2 parents 5c02cd9 + 4dd8c65 commit 092aa06
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2022 Systems Research Group, University of St Andrews:
* <https://github.com/stacs-srg>
*
* This file is part of the module population-linkage.
*
* population-linkage is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* population-linkage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with population-linkage. If not, see
* <http://www.gnu.org/licenses/>.
*/
package uk.ac.standrews.cs.population_linkage.aleks;
import org.neo4j.driver.Result;
import uk.ac.standrews.cs.neoStorr.impl.Store;
import uk.ac.standrews.cs.neoStorr.util.NeoDbCypherBridge;
import uk.ac.standrews.cs.population_linkage.graph.Query;

import java.util.List;

public class LinksCounter {

public static void main(String[] args) {
NeoDbCypherBridge bridge = Store.getInstance().getBridge();

System.out.println("Number of links for each algorithm:");
long[] numLinks = countLinks(bridge);
calculateBasicStats(numLinks);
}

private static long[] countLinks(NeoDbCypherBridge bridge) {
List <String> queries = Query.getAllLinkQueries();
List <String> algorithms = Query.getAllLinkerNames();
long[] numLinks = new long[queries.size()];

for (int i = 0; i < queries.size(); i++) {
Result result = bridge.getNewSession().run(queries.get(i));
List<Long> counts = result.list(r -> r.get("link_count").asLong());
if (!counts.isEmpty()) {
long count = counts.get(0);
numLinks[i] = count;
System.out.println((i+1) + ". " + algorithms.get(i) + " -> " + count);
}
}

return numLinks;
}

private static void calculateBasicStats(long[] numLinks) {
List <String> algorithms = Query.getAllLinkerNames();
long lowestNum = 999999999;
int lowestIndex = -1;
long highestNum = 0;
int highestIndex = -1;
long totalNum = 0;

for (int i = 0; i < numLinks.length; i++) {
if(numLinks[i] < lowestNum) {
lowestNum = numLinks[i];
lowestIndex = i;
}else if(numLinks[i] > highestNum) {
highestNum = numLinks[i];
highestIndex = i;
}

totalNum += numLinks[i];
}

System.out.println("Lowest number of links: " + algorithms.get(lowestIndex) + " -> " + lowestNum);
System.out.println("Highest number of links: " + algorithms.get(highestIndex) + " -> " + highestNum);
System.out.println("Average number of links: " + totalNum / numLinks.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public static void main(String[] args) throws Exception {
String number_of_records = args[1]; // e.g. EVERYTHING or 10000 etc.

try(
BirthBrideSiblingLinkageRecipe linkageRecipe = new BirthBrideSiblingLinkageRecipe(sourceRepo, number_of_records, BirthBrideSiblingBundleBuilder.class.getName(), null) ) {
BirthBrideIdentityLinkageRecipe linkageRecipe = new BirthBrideIdentityLinkageRecipe(sourceRepo, number_of_records, BirthBrideSiblingBundleBuilder.class.getName(), null) ) {

BitBlasterLinkageRunner runner = new BitBlasterLinkageRunner();

int linkage_fields = BirthBrideIdentityLinkageRecipe.ALL_LINKAGE_FIELDS;
int linkage_fields = linkageRecipe.ALL_LINKAGE_FIELDS;
int half_fields = linkage_fields - (linkage_fields / 2);

while (linkage_fields >= half_fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) throws Exception {
String number_of_records = args[1]; // e.g. EVERYTHING or 10000 etc.

try(
BirthDeathSiblingLinkageRecipe linkageRecipe = new BirthDeathSiblingLinkageRecipe(sourceRepo, number_of_records, BirthBrideSiblingBundleBuilder.class.getName(), null) ) {
BirthDeathSiblingLinkageRecipe linkageRecipe = new BirthDeathSiblingLinkageRecipe(sourceRepo, number_of_records, BirthDeathSiblingBundleBuilder.class.getName(), null) ) {

BitBlasterLinkageRunner runner = new BitBlasterLinkageRunner();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import uk.ac.standrews.cs.population_linkage.supportClasses.LinkageQuality;
import uk.ac.standrews.cs.population_linkage.supportClasses.LinkageResult;
import uk.ac.standrews.cs.population_records.record_types.Birth;
import uk.ac.standrews.cs.population_records.record_types.Death;
import uk.ac.standrews.cs.population_records.record_types.Marriage;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public static void main(String[] args) throws Exception {
@Override
public void makePersistent(LinkageRecipe recipe, Link link) {
try {
final String std_id1 = link.getRecord1().getReferend(Birth.class).getString(Birth.STANDARDISED_ID);
final String std_id1 = link.getRecord1().getReferend(Death.class).getString(Death.STANDARDISED_ID);
final String std_id2 = link.getRecord2().getReferend(Marriage.class).getString(Marriage.STANDARDISED_ID);

if( ! Query.DMDeathBrideOwnMarriageReferenceExists(recipe.getBridge(), std_id1, std_id2, recipe.getLinksPersistentName())) {
Expand Down
Loading

0 comments on commit 092aa06

Please sign in to comment.