forked from Luke-Sikina/picsure-search-refinement
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,185 additions
and
153 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
29 changes: 29 additions & 0 deletions
29
src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptMetaExtractor.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.concept; | ||
|
||
import edu.harvard.dbmi.avillach.dictionary.concept.model.CategoricalConcept; | ||
import edu.harvard.dbmi.avillach.dictionary.concept.model.Concept; | ||
import edu.harvard.dbmi.avillach.dictionary.concept.model.ConceptShell; | ||
import org.springframework.dao.DataAccessException; | ||
import org.springframework.jdbc.core.ResultSetExtractor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class ConceptMetaExtractor implements ResultSetExtractor<Map<Concept, Map<String, String>>> { | ||
|
||
@Override | ||
public Map<Concept, Map<String, String>> extractData(ResultSet rs) throws SQLException, DataAccessException { | ||
Map<Concept, Map<String, String>> sets = new HashMap<>(); | ||
while (rs.next()) { | ||
Concept key = new ConceptShell(rs.getString("concept_path"), rs.getString("dataset_name")); | ||
Map<String, String> meta = sets.getOrDefault(key, new HashMap<>()); | ||
meta.put(rs.getString("KEY"), rs.getString("VALUE")); | ||
sets.put(key, meta); | ||
} | ||
return sets; | ||
} | ||
} |
This file contains 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
52 changes: 52 additions & 0 deletions
52
src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptResultSetExtractor.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.concept; | ||
|
||
import edu.harvard.dbmi.avillach.dictionary.concept.model.Concept; | ||
import edu.harvard.dbmi.avillach.dictionary.concept.model.ConceptType; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.dao.DataAccessException; | ||
import org.springframework.jdbc.core.ResultSetExtractor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.*; | ||
|
||
@Component | ||
public class ConceptResultSetExtractor implements ResultSetExtractor<Concept> { | ||
@Autowired | ||
private ConceptResultSetUtil conceptResultSetUtil; | ||
|
||
private record ConceptWithId(Concept c, int id) {}; | ||
|
||
@Override | ||
public Concept extractData(ResultSet rs) throws SQLException, DataAccessException { | ||
Map<Integer, List<ConceptWithId>> conceptsByParentId = new HashMap<>(); | ||
ConceptWithId root = null; | ||
while (rs.next()) { | ||
Concept c = switch (ConceptType.toConcept(rs.getString("concept_type"))) { | ||
case Categorical -> conceptResultSetUtil.mapCategorical(rs); | ||
case Continuous -> conceptResultSetUtil.mapContinuous(rs); | ||
}; | ||
ConceptWithId conceptWithId = new ConceptWithId(c, rs.getInt("concept_node_id")); | ||
if (root == null) { root = conceptWithId; } | ||
|
||
int parentId = rs.getInt("parent_id"); | ||
// weirdness: null value for int is 0, so to check for missing parent value, you need the wasNull check | ||
if (!rs.wasNull()) { | ||
List<ConceptWithId> concepts = conceptsByParentId.getOrDefault(parentId, new ArrayList<>()); | ||
concepts.add(conceptWithId); | ||
conceptsByParentId.put(parentId, concepts); | ||
} | ||
} | ||
|
||
|
||
return root == null ? null : seedChildren(root, conceptsByParentId); | ||
} | ||
|
||
private Concept seedChildren(ConceptWithId root, Map<Integer, List<ConceptWithId>> conceptsByParentId) { | ||
List<Concept> children = conceptsByParentId.getOrDefault(root.id, List.of()).stream() | ||
.map(conceptWithId -> seedChildren(conceptWithId, conceptsByParentId)) | ||
.toList(); | ||
return root.c.withChildren(children); | ||
} | ||
} |
Oops, something went wrong.