Skip to content

Commit a988753

Browse files
committed
initial relationships working
1 parent 3552bca commit a988753

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/components/RelationshipAnnotator/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,27 @@ const LabelSelectorContainer = styled("div")({ display: "flex" })
2929
export default function RelationshipAnnotator(
3030
props: RelationshipAnnotatorProps
3131
) {
32-
console.log({ props })
3332
const [highlightedItems, changeHighlightedItems] = useState([])
34-
const [relationships, setRelationships] = useState(props.relationships || [])
33+
const [relationships, setRelationships] = useState(
34+
props.initialRelationships || []
35+
)
3536
const [activePair, setActivePair] = useState(null)
3637
const [creatingRelationships, setCreatingRelationships] = useState(true)
37-
const [sequence, changeSequence] = useState(() =>
38-
props.initialSequence
38+
const [sequence, changeSequence] = useState(() => {
39+
const textIdsInRelationship = new Set(
40+
relationships.flatMap(({ to, from }) => [to, from])
41+
)
42+
return props.initialSequence
3943
? props.initialSequence.flatMap(entity =>
40-
entity.label
44+
entity.label ||
45+
(entity.textId && textIdsInRelationship.has(entity.textId))
4146
? [withId(entity)]
4247
: stringToSequence(entity.text, props.separatorRegex).map(withId)
4348
)
4449
: stringToSequence(props.document).map(withId)
45-
)
50+
})
51+
52+
console.log(sequence, relationships)
4653

4754
const labels = creatingRelationships
4855
? props.relationshipLabels

src/components/RelationshipAnnotator/index.story.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ storiesOf("RelationshipAnnotator", module)
4545
type="label-relationships"
4646
document={`Lorem ipsum dolor.`}
4747
initialSequence={[
48-
{ label: "noun", text: "Lorem" },
49-
{ text: " ipsum " },
50-
{ label: "proper-noun", text: "dolor." },
51-
{ text: " this should be broken up into words." }
48+
{ label: "noun", text: "Lorem", textId: "lorem" },
49+
{ text: " ipsum ", textId: "ipsum" },
50+
{ label: "proper-noun", text: "dolor.", textId: "dolor" },
51+
{ text: " this should be broken up into words.", textId: "therest" }
5252
]}
53+
initialRelationships={[{ from: "lorem", to: "ipsum", label: "eaten-by" }]}
5354
entityLabels={[
5455
{
5556
color: colors[0],

0 commit comments

Comments
 (0)