Skip to content

Commit

Permalink
Extract geolocation information when enriching model AMR (#5519)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvince2 authored Dec 10, 2024
1 parent 003dff2 commit b378534
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export interface DKG {
curie: string;
name: string;
description: string;
locations?: string[];
}

export interface EntitySimilarityResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ public ResponseEntity<Dataset> postProfileDataset(
if (groundings.getIdentifiers() == null) {
groundings.setIdentifiers(new ArrayList<>());
}
groundings.getIdentifiers().add(new DKG(g.get(0).asText(), g.get(1).asText(), ""));
groundings.getIdentifiers().add(new DKG(g.get(0).asText(), g.get(1).asText(), "", null, null));
}

// remove groundings from an annotation object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.annotation.PostConstruct;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -21,17 +22,20 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import software.uncharted.terarium.hmiserver.models.dataservice.Artifact;
import software.uncharted.terarium.hmiserver.models.dataservice.model.Model;
import software.uncharted.terarium.hmiserver.models.dataservice.model.configurations.ModelConfiguration;
import software.uncharted.terarium.hmiserver.models.mira.Curies;
import software.uncharted.terarium.hmiserver.models.mira.DKG;
import software.uncharted.terarium.hmiserver.models.mira.EntitySimilarityResult;
import software.uncharted.terarium.hmiserver.models.task.TaskRequest;
import software.uncharted.terarium.hmiserver.models.task.TaskRequest.TaskType;
Expand Down Expand Up @@ -107,6 +111,28 @@ void init() {
taskService.addResponseHandler(sbmlToPetrinetResponseHandler);
}

@GetMapping("/geoname-search")
@Secured(Roles.USER)
public ResponseEntity<DKG> search(@RequestParam("q") final String q) {
final DKG finalResponse = new DKG(q);
try {
for (String s : q.split("_")) {
ResponseEntity<List<DKG>> response = proxy.search(q, 1, 0);
if (
response.getBody() == null &&
!response.getBody().isEmpty() &&
response.getBody().get(0).getLabels().contains(DKG.GEONAMES)
) {
finalResponse.getLocations().add(response.getBody().get(0).getCurie());
}
}
} catch (final FeignException e) {
throw handleMiraFeignException(e, "concepts", "query", q, "mira.concept.bad-query");
}

return new ResponseEntity<>(finalResponse, HttpStatus.OK);
}

@PostMapping("/amr-to-mmt")
@Secured(Roles.USER)
@Operation(summary = "convert AMR to MIRA model template")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import software.uncharted.terarium.hmiserver.annotations.TSIgnore;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.annotations.TSOptional;

@Data
@Accessors(chain = true)
Expand All @@ -22,6 +28,12 @@ public class DKG {
public static final String NAME = "name:string";
public static final String DESCRIPTION = "description:string";
public static final String EMBEDDINGS = "description:dense_vector";
public static final String GEONAMES = "geonames";

public DKG(String curie) {
this.curie = curie;
locations = new ArrayList<>();
}

@JsonAlias(ID)
private String curie;
Expand All @@ -32,4 +44,19 @@ public class DKG {
@JsonAlias(DESCRIPTION)
@JsonSetter(nulls = Nulls.AS_EMPTY)
private String description = "";

@TSIgnore
private List<String> labels;

@TSOptional
private List<String> locations;

public void addLocations(DKG locationInformation) {
if (locationInformation.getLocations() != null) {
if (this.locations == null) {
this.locations = new ArrayList<>();
}
this.locations.addAll(locationInformation.getLocations());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import software.uncharted.terarium.hmiserver.models.dataservice.model.Model;
import software.uncharted.terarium.hmiserver.models.mira.Curies;
import software.uncharted.terarium.hmiserver.models.mira.DKG;
import software.uncharted.terarium.hmiserver.models.mira.EntitySimilarityResult;

@FeignClient(name = "mira-api", url = "${mira-api.url}", path = "/api")
Expand All @@ -23,4 +25,8 @@ public interface MIRAProxy {

@PostMapping("/entity_similarity")
ResponseEntity<List<EntitySimilarityResult>> entitySimilarity(@RequestBody Curies obj) throws FeignException;

@PostMapping("/search")
ResponseEntity<List<DKG>> search(@RequestBody String q, @RequestParam Integer limit, @RequestParam Integer offset)
throws FeignException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Grounding createGrounding(final String key) {
final Grounding grounding = new Grounding();
grounding.setContext(mapper.createObjectNode().put("hello", "world-" + key).put("foo", "bar-" + key));
grounding.setIdentifiers(new ArrayList<>());
grounding.getIdentifiers().add(new DKG("curie", "maria", ""));
grounding.getIdentifiers().add(new DKG("curie", "maria", "", null, null));
return grounding;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static Grounding createGrounding(final String key) {
final Grounding grounding = new Grounding();
grounding.setContext(mapper.createObjectNode().put("hello", "world-" + key).put("foo", "bar-" + key));
grounding.setIdentifiers(new ArrayList<>());
grounding.getIdentifiers().add(new DKG("curie", "maria", ""));
grounding.getIdentifiers().add(new DKG("curie", "maria", "", null, null));
return grounding;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static Grounding createGrounding(final String key) {
final Grounding grounding = new Grounding();
grounding.setContext(objectMapper.createObjectNode().put("hello", "world-" + key).put("foo", "bar-" + key));
grounding.setIdentifiers(new ArrayList<>());
grounding.getIdentifiers().add(new DKG("curie", "maria", ""));
grounding.getIdentifiers().add(new DKG("curie", "maria", "", null, null));
return grounding;
}

Expand Down

0 comments on commit b378534

Please sign in to comment.