Skip to content

Commit

Permalink
hot fix for sentence structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelpiano committed Dec 20, 2023
1 parent 5bc0128 commit 1c26197
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
32 changes: 20 additions & 12 deletions backend/composer/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,36 +469,44 @@ def get_statement_preview(self, instance):
return self.create_statement_preview(instance, self.context['journey'])

def create_statement_preview(self, instance, journey):
sex = instance.sex.name if instance.sex else "{sex}"
sex = instance.sex.name if instance.sex else ""
species_list = [specie.name for specie in instance.species.all()]
species = join_entities(species_list)
if not species:
species = "{species}"
species = ""

phenotype = instance.phenotype.name.lower() if instance.phenotype else "{phenotype}"
phenotype = instance.phenotype.name.lower() if instance.phenotype else ""
origin_names = [origin.name for origin in instance.origins.all()]
origins = join_entities(origin_names)
if not origins:
origins = "{species}"
origins = ""

circuit_type = instance.get_circuit_type_display().lower() if instance.circuit_type else "{circuit_type}"
projection = instance.get_projection_display().lower() if instance.projection else "{projection}"
circuit_type = instance.get_circuit_type_display().lower() if instance.circuit_type else ""
projection = instance.get_projection_display().lower() if instance.projection else ""

laterality_description = instance.get_laterality_description()
if not laterality_description:
laterality_description = "{laterality_description}"
laterality_description = ""

forward_connection = (
join_entities(instance.forward_connection.all().values_list('id', flat=True))
if instance.forward_connection
else "{forward_connection}"
else ""
)
apinatomy = instance.apinatomy_model if instance.apinatomy_model else "{apinatomy}"
journey_sentence = '\n'.join(journey)
apinatomy = instance.apinatomy_model if instance.apinatomy_model else ""
journey_sentence = ', '.join(journey)

# Creating the statement
statement = f"In a {sex} {species}, a {phenotype} connection goes: \n{journey_sentence}\n"
statement += f"This {projection} {circuit_type} connection projects from the {origins} and is found {laterality_description}."
if sex != "" or species != "":
statement = f"In a {sex} {species}, a {phenotype} connection goes {journey_sentence}.\n"
else:
statement = f"A {phenotype} connection goes {journey_sentence}.\n"
statement += f"This "
if projection != "not specified":
statement += f"{projection} "
if circuit_type != "not specified":
statement += f"{circuit_type} "
statement += f"connection projects from the {origins} and is found {laterality_description}.\n"

if forward_connection:
statement += f" This neuron population connects to connectivity statements with id {forward_connection}."
Expand Down
2 changes: 1 addition & 1 deletion backend/composer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def get_laterality_description(self):
laterality_map = {
Laterality.RIGHT.value: "on the right side of the body",
Laterality.LEFT.value: "on the left side of the body",
Laterality.UNKNOWN.value: "at an unknown location",
Laterality.UNKNOWN.value: "at an unknown location of the body",
}
return laterality_map.get(self.laterality, "at an unknown location")

Expand Down
4 changes: 2 additions & 2 deletions backend/composer/services/state_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def compile_journey(connectivity_statement) -> List[str]:
via_names = ' via '.join([node for node, layer in path if 0 < layer < len(vias) + 1])

if via_names:
sentence = f"From {origin_names} to {destination_names} via {via_names}."
sentence = f"from {origin_names} to {destination_names} via {via_names}"
else:
sentence = f"From {origin_names} to {destination_names}."
sentence = f"from {origin_names} to {destination_names}"

journey_descriptions.append(sentence)

Expand Down
14 changes: 11 additions & 3 deletions frontend/src/components/ProofingTab/ProofingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ const ProofingTab = (props: any) => {
</Box>
<Stack spacing={2}>
<Typography variant="h5">Journey</Typography>
{statement.journey.map((journeyStep: string, index: number) => (
<Typography key={index}>{journeyStep}</Typography>
))}
{statement.journey.map((journeyStep: string, index: number) => {
if (index === 0) {
return <>{journeyStep.charAt(0).toUpperCase() + journeyStep.slice(1)}, </>;
} else {
if (index === statement.journey.length - 1) {
return <>{journeyStep}.</>;
} else {
return <>{journeyStep}, </>;
}
}
})}
</Stack>
</>
)}
Expand Down

0 comments on commit 1c26197

Please sign in to comment.