Skip to content

Commit

Permalink
* Updated the claim-gen importer to work with the latest claim-gen ex…
Browse files Browse the repository at this point in the history
…ports. (which includes "evidence" entries, which have polarity, ie. are supporting or opposing their parent)
  • Loading branch information
Venryx committed May 22, 2024
1 parent 70a914e commit 8799303
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ class ImportSubtreeUI extends BaseComponent<
</Column>}
<Column style={{width: 800, padding: "0 5px"}}>
<Row>
<Select displayType="button bar" options={GetEntries(ImportSubtreeUI_RightTab, "ui")} value={rightTab} onChange={val=>this.SetState({rightTab: val})}/>
<CheckBox ml={5} text="Show left panel" value={showLeftPanel} onChange={val=>this.SetState({showLeftPanel: val})}/>
{/*<Select displayType="button bar" options={GetEntries(ImportSubtreeUI_RightTab, "ui")} value={rightTab} onChange={val=>this.SetState({rightTab: val})}/>*/}
<CheckBox /*ml={5}*/ text="Show left panel" value={showLeftPanel} onChange={val=>this.SetState({showLeftPanel: val})}/>
<Row ml="auto">
<CheckBox text="Extract resources" value={process} onChange={val=>this.SetState({process: val})}/>
<CheckBox text={[`Extract resources`, resources.length > 0 && `(${resources.length})`].filter(a=>a).join(" ")} value={process} onChange={val=>this.SetState({process: val})}/>
<CheckBox ml={5} text={`Import selected (${importProgressStr})`} enabled={!serverImportInProgress} value={this.nodeCreationTimer.Enabled} onChange={val=>{
this.SetTimerEnabled(val);
this.SetState({selectedIRs_nodeAndRev_atImportStart: selectedIRs_nodeAndRev.length});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Attachment, AttachmentType, QuoteAttachment, Source, SourceChain, SourceType} from "dm_common";
import {Attachment, AttachmentType, DescriptionAttachment, QuoteAttachment, Source, SourceChain, SourceType} from "dm_common";
import {IsString} from "js-vextensions";

export type CG_RefURLOrQuoteOld = string | CG_QuoteOld;
Expand All @@ -25,7 +25,7 @@ export abstract class CG_Node {
/** Get the regular, "standalone" text of the claim. (stored in debate-map as text_base) */
static GetTitle_Main(node: CG_Node): string {
const d = node as any;
const result_raw = d.name ?? (d.questionText ?? d.question) ?? d.position ?? d.category ?? d.claim ?? d.argument;
const result_raw = d.name ?? (d.questionText ?? d.question) ?? d.position ?? d.category ?? d.claim ?? d.argument ?? d.original_example ?? d.quote;
const result = (result_raw ?? "").trim(); // fsr, some json files contain line-breaks at start or end, so clean this up
return result.length ? result : null;
}
Expand Down Expand Up @@ -75,6 +75,29 @@ export abstract class CG_Node {
}));
}

if (CG_Evidence.is(node)) {
const evidence = node as CG_Evidence;
if (evidence.url) {
result.push(new Attachment({
quote: new QuoteAttachment({
content: evidence.quote,
sourceChains: evidence.url != null ? [
new SourceChain([
new Source({type: SourceType.webpage, link: evidence.url}),
]),
] : [],
}),
}));
}
if (evidence.reasoning) {
result.push(new Attachment({
description: new DescriptionAttachment({
text: evidence.reasoning,
}),
}));
}
}

return result;
}
}
Expand Down Expand Up @@ -110,15 +133,34 @@ export class CG_Claim extends CG_Node {
similarity?: boolean;
edited?: boolean;*/

// v2 (tool extending claim-gen)
//arguments?: string[];

// v3 (tool extending claim-gen)
arguments?: (string | CG_Argument)[];

// v4
counter_claim?: string;

// v5
examples?: CG_Argument[];
counter_claims?: string[];
}

// the distinction between "argument" and "example" is a bit unclear to me in the claimgen model; merging them atm
export class CG_Argument extends CG_Node {
argument: string;
// when in "arguments" collection
argument?: string;

// when in "examples" collection
original_example?: string;
evidence?: CG_Evidence[];
}

export class CG_Evidence extends CG_Node {
quote: string;
url: string;
stance: "supports" | "refutes";
reasoning: string;

static is(node: CG_Node) {
return (node as any).stance != null;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {IR_NodeAndRevision, ImportResource} from "Utils/DataFormats/DataExchangeFormat.js";
import {CreateAccessor, GenerateUUID} from "mobx-graphlink";
import {ArgumentType, Attachment, ChildGroup, ClaimForm, CullNodePhrasingToBeEmbedded, GetSystemAccessPolicyID, NodeL1, NodeLink, NodePhrasing, NodePhrasingType, NodeRevision, NodeType, OrderKey, systemUserID} from "dm_common";
import {ArgumentType, Attachment, ChildGroup, ClaimForm, CullNodePhrasingToBeEmbedded, GetSystemAccessPolicyID, NodeL1, NodeLink, NodePhrasing, NodePhrasingType, NodeRevision, NodeType, OrderKey, Polarity, systemUserID} from "dm_common";
import {Assert, IsString} from "js-vextensions";
import {AddNotificationMessage} from "web-vcore";
import {CG_Argument, CG_Category, CG_Claim, CG_Debate, CG_Node, CG_Position, CG_Question} from "./DataModel.js";
import {CG_Argument, CG_Category, CG_Claim, CG_Debate, CG_Evidence, CG_Node, CG_Position, CG_Question} from "./DataModel.js";

export class ImportContext {
mapID: string;
Expand Down Expand Up @@ -56,13 +56,27 @@ export const GetResourcesInClaim_CG = CreateAccessor((context: ImportContext, cl
const args = [] as CG_Argument[];
if (claim.argument) args.push({argument: claim.argument} as CG_Argument);
if (claim.arguments) args.push(...claim.arguments.map(a=>(IsString(a) ? {argument: a} : a)) as CG_Argument[]);
if (claim.counter_claim) args.push({argument: claim.counter_claim} as CG_Argument);
if (claim.examples) args.push(...claim.examples);
const counterClaimStrings = [...(claim.counter_claims ?? []), ...(claim.counter_claim ? [claim.counter_claim] : [])];
args.push(...counterClaimStrings.map(str=>({argument: str} as CG_Argument)));
for (const [i, argument] of args.entries()) {
result.push(NewNodeResource(context, argument, NodeType.claim, path_indexes.concat(i), path_titles.concat(argument.argument), claimResource, ChildGroup.freeform));
result.push(...GetResourcesInArgument_CG(context, argument, path_indexes.concat(i), path_titles.concat(CG_Node.GetTitle_Main(argument)), claimResource));
}

return result;
});
export const GetResourcesInArgument_CG = CreateAccessor((context: ImportContext, argument: CG_Argument, path_indexes: number[], path_titles: string[], parentResource: ImportResource)=>{
const result = [] as ImportResource[];
const argumentResource = NewNodeResource(context, argument, NodeType.claim, path_indexes, path_titles, parentResource, ChildGroup.freeform);
result.push(argumentResource);

for (const [i, evidence] of (argument.evidence ?? []).entries()) {
result.push(NewNodeResource(context, evidence, NodeType.claim, path_indexes.concat(i), path_titles.concat(CG_Node.GetTitle_Main(evidence)), argumentResource, ChildGroup.truth));
}

return result;
});

let hasWarned_id = false;
export const NewNodeResource = CreateAccessor((context: ImportContext, data: CG_Node, nodeType: NodeType, path_indexes: number[], path_titles: string[], parentResource: ImportResource|n, childGroup = ChildGroup.generic, claimForm?: ClaimForm)=>{
if (data.id != null && !hasWarned_id) {
Expand Down Expand Up @@ -95,6 +109,10 @@ export const NewNodeResource = CreateAccessor((context: ImportContext, data: CG_
orderKey: orderKey.toString(),
form: claimForm,
});
if (CG_Evidence.is(data)) {
const evidence = data as CG_Evidence;
link.polarity = evidence.stance == "supports" ? Polarity.supporting : Polarity.opposing;
}

const mainTitle = CG_Node.GetTitle_Main(data);
const narrativeTitle = CG_Node.GetTitle_Narrative(data);
Expand Down

0 comments on commit 8799303

Please sign in to comment.