Skip to content

Commit

Permalink
Merge pull request #94 from VirtualFlyBrain/split-_edges
Browse files Browse the repository at this point in the history
Split  edges
  • Loading branch information
Robbie1977 authored Sep 1, 2024
2 parents c59dad4 + 73fea97 commit 031b5f4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ebi/spot/neo4j2owl/N2OProcedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public Stream<N2OReturnValue> exportOWLNodes(@Name("skip") Long skip, @Name("lim

@SuppressWarnings("unused")
@Procedure(mode = Mode.WRITE)
public Stream<N2OReturnValue> exportOWLEdges() {
public Stream<N2OReturnValue> exportOWLEdges(@Name("relationType") String relationType, @Name("currentChunk") int currentChunk, @Name("limit") int chunkCount) {
logger.resetTimer();
N2OExportService exportService = new N2OExportService(db);
N2OReturnValue result = exportService.owl2ExportEdges();
N2OReturnValue result = exportService.owl2ExportEdges(relationType, currentChunk, chunkCount);
return Stream.of(result);
}

Expand Down
52 changes: 44 additions & 8 deletions src/main/java/ebi/spot/neo4j2owl/exporter/N2OExportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public class N2OExportService {
// static IRIManager iriManager = new IRIManager();
private N2OExportManager n2OEntityManager;
private Set<String> qsls_with_no_matching_properties;


private final static String SUBCLASS_OF = "subclassOf";
private final static String INSTANCE_OF = "instanceOf";
private final static String ANNOTATION_PROPERTY = "annotationProperty";
private final static String OBJECT_PROPERTY = "objectProperty";

public N2OExportService(GraphDatabaseService db) {
this.db = db;
}
Expand Down Expand Up @@ -115,7 +120,7 @@ public N2OReturnValue owl2ExportNodes(Long skip, Long limit) {
return returnValue;
}

public N2OReturnValue owl2ExportEdges() {
public N2OReturnValue owl2ExportEdges(String relationType, int currentChunk, int chunkCount) {
n2OEntityManager = new N2OExportManager();
qsls_with_no_matching_properties = new HashSet<>();
logger.resetTimer();
Expand All @@ -126,13 +131,23 @@ public N2OReturnValue owl2ExportEdges() {

OWLOntology o = man.createOntology();
findEntities(0L, Long.MAX_VALUE);
addRelation(o, N2OStatic.RELTYPE_SUBCLASSOF);
addRelation(o, N2OStatic.RELTYPE_INSTANCEOF);
for (String rel_qsl : getRelations(OWLAnnotationProperty.class)) {
addRelation(o, rel_qsl);
if (relationType == null || relationType.isEmpty() || relationType.equals(SUBCLASS_OF)) {
addRelation(o, N2OStatic.RELTYPE_SUBCLASSOF);
}
for (String rel_qsl : getRelations(OWLObjectProperty.class)) {
addRelation(o, rel_qsl);
if (relationType == null || relationType.isEmpty() || relationType.equals(INSTANCE_OF)) {
addRelation(o, N2OStatic.RELTYPE_INSTANCEOF);
}
if (relationType == null || relationType.isEmpty() || relationType.equals(ANNOTATION_PROPERTY)) {
for (String rel_qsl : getRelations(OWLAnnotationProperty.class)) {
addRelation(o, rel_qsl);
}
}
if (relationType == null || relationType.isEmpty() || relationType.equals(OBJECT_PROPERTY)) {
Set<String> objRelations = getRelations(OWLObjectProperty.class);
List<Set<String>> chunks = splitSet(objRelations, chunkCount);
for (String rel_qsl : chunks.get(currentChunk)) {
addRelation(o, rel_qsl);
}
}
ByteArrayOutputStream os = new ByteArrayOutputStream(); // new FileOutputStream(new File(fileName))
man.saveOntology(o, new RDFXMLDocumentFormat(), os);
Expand Down Expand Up @@ -479,4 +494,25 @@ private int safeAdd(int number, int increment, int maxValue) {
// test < number on integer overflow
return (test < number || test > maxValue) ? maxValue : test;
}


/**
* Splits given set into given number of chunks.
* @param set to split
* @param numChunks number of chunks
* @return List of subsets
*/
public static <T> List<Set<T>> splitSet(Set<T> set, int numChunks) {
List<Set<T>> chunks = new ArrayList<>();
List<T> list = new ArrayList<>(set);
int chunkSize = (int) Math.ceil((double) list.size() / numChunks);

for (int i = 0; i < list.size(); i += chunkSize) {
int end = Math.min(list.size(), i + chunkSize);
chunks.add(new HashSet<>(list.subList(i, end)));
}

return chunks;
}

}

0 comments on commit 031b5f4

Please sign in to comment.