Skip to content

Commit

Permalink
Dereference unconnected blank nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
compulim committed Mar 18, 2024
1 parent e2ca95c commit bb19e29
Show file tree
Hide file tree
Showing 17 changed files with 506 additions and 38 deletions.
43 changes: 19 additions & 24 deletions __tests__/html/linkDefinition/badge.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@
'@type': 'DigitalDocument',
url: 'https://example.com/1/',
usageInfo: {
'@id': '_:1',
'@type': 'CreativeWork',
description:
'Nisi quis ut sint elit est nulla enim eiusmod. Deserunt commodo pariatur nostrud culpa aliquip esse pariatur exercitation nulla do proident. Est qui eiusmod aliquip deserunt labore consequat fugiat. Ullamco reprehenderit nostrud eiusmod nisi nulla esse id. Reprehenderit aliqua quis consectetur sit cupidatat fugiat Lorem ex labore. Eiusmod velit laborum quis tempor incididunt excepteur culpa esse nulla.',
name: 'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat'
keywords: ['encrypted-content'],
name: 'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat',
pattern: {
'@type': 'DefinedTerm',
inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/',
name: 'color',
termCode: 'orange'
}
}
}
},
Expand All @@ -51,7 +59,13 @@
text: 'Incididunt amet dolore anim commodo fugiat occaecat elit nulla do consequat. Quis incididunt occaecat labore adipisicing. Cillum sunt velit consequat irure ipsum ullamco sint ea aute. Sunt et eu ut enim aliqua cupidatat non adipisicing dolore commodo dolor magna enim. Commodo reprehenderit excepteur ad nostrud ex id aliquip deserunt eiusmod. Esse non labore nulla voluptate.',
usageInfo: {
'@type': 'CreativeWork',
name: 'Velit exercitation'
name: 'Velit exercitation',
pattern: {
'@type': 'DefinedTerm',
inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/',
name: 'color',
termCode: 'Yellow'
}
}
}
},
Expand All @@ -65,26 +79,7 @@
}
],
type: 'https://schema.org/Message',
usageInfo: {
'@type': 'CreativeWork',
description:
'Cillum elit cupidatat anim nulla reprehenderit proident excepteur aute consectetur culpa ad deserunt do aliquip.',
keywords: [
{
'@type': 'DefinedTerm',
additionalType: 'https://copilotstudio.microsoft.com/encryption-status/v1',
name: 'encryptionStatus',
termCode: 'encrypted'
}
],
name: 'Enim deserunt irure ut proident sunt eiusmod dolor laboris sunt nulla occaecat.',
pattern: {
'@type': 'DefinedTerm',
inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/',
name: 'color',
termCode: 'orange'
}
}
usageInfo: { '@id': '_:1' }
}
],
text: 'Ipsum[1] dolore[2] cupidatat[3] magna[4] consectetur[5] do tempor est excepteur.\n\n[1]: https://example.com/1/ "Sint amet id officia dolor ex eiusmod ipsum ipsum magna fugiat"\n[2]: https://example.com/2/ "Laboris cupidatat voluptate"\n[3]: _:3 "Velit nulla culpa eu ea consectetur consectetur dolore velit"\n[4]: _:4 "Adipisicing enim nulla"\n[5]: https://example.com/5',
Expand Down Expand Up @@ -136,12 +131,12 @@

expect(document.querySelector('.webchat__link-definitions__message-sensitivity-label-text')).toHaveProperty(
'textContent',
'Enim deserunt irure ut proident sunt eiusmod dolor laboris sunt nulla occaecat.'
'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat'
);

expect(document.querySelector('.webchat__link-definitions__message-sensitivity-label')).toHaveProperty(
'title',
'Enim deserunt irure ut proident sunt eiusmod dolor laboris sunt nulla occaecat.\n\nCillum elit cupidatat anim nulla reprehenderit proident excepteur aute consectetur culpa ad deserunt do aliquip.'
'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat\n\nNisi quis ut sint elit est nulla enim eiusmod. Deserunt commodo pariatur nostrud culpa aliquip esse pariatur exercitation nulla do proident. Est qui eiusmod aliquip deserunt labore consequat fugiat. Ullamco reprehenderit nostrud eiusmod nisi nulla esse id. Reprehenderit aliqua quis consectetur sit cupidatat fugiat Lorem ex labore. Eiusmod velit laborum quis tempor incididunt excepteur culpa esse nulla.'
);
});
</script>
Expand Down
11 changes: 11 additions & 0 deletions packages/component/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"botframework-webchat-core": "0.0.0-0",
"classnames": "2.3.2",
"compute-scroll-into-view": "1.0.20",
"deep-freeze-strict": "^1.1.1",
"event-target-shim": "6.0.2",
"markdown-it": "13.0.2",
"math-random": "2.0.1",
Expand Down
15 changes: 8 additions & 7 deletions packages/component/src/ActivityStatus/OthersActivityStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import classNames from 'classnames';
import React, { memo, useMemo, type ReactNode } from 'react';

import useStyleSet from '../hooks/useStyleSet';
import dereferenceBlankNodes from '../Utils/JSONLinkedData/dereferenceBlankNodes';
import Feedback from './private/Feedback/Feedback';
import Originator from './private/Originator';
import Slotted from './Slotted';
Expand All @@ -25,24 +26,24 @@ const warnRootLevelThings = warnOnce(
const OthersActivityStatus = memo(({ activity }: Props) => {
const [{ sendStatus }] = useStyleSet();
const { timestamp } = activity;
const entities = useMemo(() => activity.entities || [], [activity]);
const messageThing = useMemo(() => getOrgSchemaMessage(activity), [activity]);
const graph = useMemo(() => dereferenceBlankNodes(activity.entities || []), [activity.entities]);
const messageThing = useMemo(() => getOrgSchemaMessage(graph), [graph]);

const claimInterpreter = useMemo<OrgSchemaProject2 | undefined>(() => {
try {
if (messageThing) {
return parseClaim((messageThing?.citation || [])[0])?.claimInterpreter;
}

const [firstClaim] = entities.filter(({ type }) => type === 'https://schema.org/Claim').map(parseClaim);
const [firstClaim] = graph.filter(({ type }) => type === 'https://schema.org/Claim').map(parseClaim);

if (firstClaim) {
warnRootLevelThings();

return firstClaim?.claimInterpreter;
}

const replyAction = parseAction(entities.find(({ type }) => type === 'https://schema.org/ReplyAction'));
const replyAction = parseAction(graph.find(({ type }) => type === 'https://schema.org/ReplyAction'));

if (replyAction) {
warnRootLevelThings();
Expand All @@ -52,7 +53,7 @@ const OthersActivityStatus = memo(({ activity }: Props) => {
} catch {
// Intentionally left blank.
}
}, [entities, messageThing]);
}, [graph, messageThing]);

const feedbackActions = useMemo<ReadonlySet<OrgSchemaAction2> | undefined>(() => {
try {
Expand All @@ -64,15 +65,15 @@ const OthersActivityStatus = memo(({ activity }: Props) => {
return Object.freeze(new Set(reactActions));
}

const voteActions = entities.filter(({ type }) => type === 'https://schema.org/VoteAction').map(parseAction);
const voteActions = graph.filter(({ type }) => type === 'https://schema.org/VoteAction').map(parseAction);

if (voteActions.length) {
return Object.freeze(new Set(voteActions));
}
} catch {
// Intentionally left blank.
}
}, [entities, messageThing]);
}, [graph, messageThing]);

return (
<Slotted className={classNames('webchat__activity-status', sendStatus + '')}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, { memo, useCallback, useMemo, type MouseEventHandler } from 'react
import { useRefFrom } from 'use-ref-from';

import { LinkDefinitionItem, LinkDefinitions } from '../../../LinkDefinition/index';
import dereferenceBlankNodes from '../../../Utils/JSONLinkedData/dereferenceBlankNodes';
import useRenderMarkdownAsHTML from '../../../hooks/useRenderMarkdownAsHTML';
import useStyleSet from '../../../hooks/useStyleSet';
import useShowModal from '../../../providers/ModalDialog/useShowModal';
Expand Down Expand Up @@ -50,10 +51,12 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
}
] = useStyleSet();
const localize = useLocalizer();
const messageThing = useMemo(() => getOrgSchemaMessage(activity), [activity]);
const graph = useMemo(() => dereferenceBlankNodes(activity.entities || []), [activity.entities]);
const renderMarkdownAsHTML = useRenderMarkdownAsHTML();
const showModal = useShowModal();

const messageThing = useMemo(() => getOrgSchemaMessage(graph), [graph]);

const citationModalDialogLabel = localize('CITATION_MODEL_DIALOG_ALT');

if (!renderMarkdownAsHTML) {
Expand Down Expand Up @@ -106,7 +109,7 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
};
}

const rootLevelClaim = (activity.entities || [])
const rootLevelClaim = graph
.filter(({ type }) => type === 'https://schema.org/Claim')
.map(parseClaim)
.find(({ '@id': id }) => id === markdownDefinition.url);
Expand All @@ -129,7 +132,7 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
};
})
),
[activity, markdownDefinitions, messageThing, showClaimModal]
[graph, markdownDefinitions, messageThing, showClaimModal]
);

const entriesRef = useRefFrom(entries);
Expand Down
4 changes: 2 additions & 2 deletions packages/component/src/LinkDefinition/LinkDefinitionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import ItemBody from './private/ItemBody';
import extractHostnameWithSubdomain from './private/extractHostnameWithSubdomain';

type Props = Readonly<{
badgeName?: string; // TODO: Should we name this "badgeBody"?
badgeTitle?: string; // TODO: Should we name this "badgeTitle"?
badgeName?: string;
badgeTitle?: string;
identifier?: string;
onClick?: (event: Pick<CustomEvent, 'defaultPrevented' | 'preventDefault' | 'type'>) => void;
text?: string;
Expand Down
13 changes: 13 additions & 0 deletions packages/component/src/Utils/JSONLinkedData/BlankNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* A blank node identifier is a string starting with `"_:"`
*
* @see https://json-ld.github.io/json-ld.org/spec/latest/json-ld/#dfn-blank-node-identifiers
*/
export type BlankNodeIdentifier = `_:${string}`;

/**
* A blank node is a node with `@id` starting with `"_:"`
*
* @see https://json-ld.github.io/json-ld.org/spec/latest/json-ld/#dfn-blank-nodes
*/
export type BlankNode = { '@id': BlankNodeIdentifier };
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should dereference unconnected blank nodes in array in cyclic fashion 1`] = `
Object {
"@type": "Book",
"about": Array [
Object {
"@id": "_:isaac",
"@type": "Person",
"name": "Isaac Stevens",
"worksFor": Object {
"@id": "_:uw",
"@type": "Organization",
"founder": [Circular],
"name": "University of Washington",
},
},
Object {
"@id": "_:uw",
"@type": "Organization",
"founder": Object {
"@id": "_:isaac",
"@type": "Person",
"name": "Isaac Stevens",
"worksFor": [Circular],
},
"name": "University of Washington",
},
],
"author": Object {
"@type": "Person",
"name": "Edmond S. Meany",
},
"name": "Governors of Washington: territorial and state",
}
`;

exports[`should dereference unconnected blank nodes in cyclic fashion 1`] = `
Object {
"@type": "Book",
"author": Object {
"@id": "_:isaac",
"@type": "Person",
"name": "Isaac Stevens",
"worksFor": Object {
"@id": "_:uw",
"@type": "Organization",
"founder": [Circular],
"name": "University of Washington",
},
},
"name": "Report of Explorations for a Route for the Pacific Railroad near the 47th and 49th Parallels of North Latitude, from St. Paul, Minnesota, to Puget Sound",
"sourceOrganization": Object {
"@id": "_:uw",
"@type": "Organization",
"founder": Object {
"@id": "_:isaac",
"@type": "Person",
"name": "Isaac Stevens",
"worksFor": [Circular],
},
"name": "University of Washington",
},
}
`;

exports[`should dereference unconnected blank nodes in the graph 1`] = `
Array [
Object {
"@id": "_:isaac",
"@type": "Person",
"name": "Isaac Stevens",
"worksFor": Object {
"@id": "_:uw",
"@type": "Organization",
"founder": [Circular],
"name": "University of Washington",
},
},
Object {
"@id": "_:uw",
"@type": "Organization",
"founder": Object {
"@id": "_:isaac",
"@type": "Person",
"name": "Isaac Stevens",
"worksFor": [Circular],
},
"name": "University of Washington",
},
]
`;
Loading

0 comments on commit bb19e29

Please sign in to comment.