Skip to content

Instantly share code, notes, and snippets.

@Venryx
Created March 27, 2018 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Venryx/260288d75f403fb5a5b29127ec8c9c9f to your computer and use it in GitHub Desktop.
Save Venryx/260288d75f403fb5a5b29127ec8c9c9f to your computer and use it in GitHub Desktop.
Reason Score - First Attempt
import { MapNodeL3 } from "Store/firebase/nodes/@MapNode";
import { GetNodeChildrenL2, GetNodeChildrenL3 } from "Store/firebase/nodes";
import {MapNodeL2, Polarity} from "../nodes/@MapNode";
import {IsSpecialEmptyArray, emptyArray_forLoading} from "../../../Frame/Store/ReducerUtils";
import {GetFinalPolarity} from "../nodes/$node";
import {MapNodeType} from "../nodes/@MapNodeType";
export function ReasonScore_CalculateTruthScore(node: MapNodeL3) {
Assert(node.type == MapNodeType.Claim, "RS truth-score can only be calculated for a claim.");
let childArguments = GetNodeChildrenL3(node);
if (childArguments == emptyArray_forLoading || childArguments.Any(a=>a == null)) return 100; // if still loading, return 100
for (let child of childArguments) {
let childChildren = GetNodeChildrenL3(child);
if (childChildren == emptyArray_forLoading || childChildren.Any(a=>a == null)) return 100; // if still loading, return 100
}
// if no child arguments, return 100
if (childArguments.length == 0) return 100;
let childScores_forAveraging = [];
for (let childArgument of childArguments) {
let childClaim = GetNodeChildrenL3(childArgument).filter(a=>a.type == MapNodeType.Claim)[0];
if (childClaim == null) continue;
let childTruthScore = ReasonScore_CalculateTruthScore(childClaim);
let childTruthScore_distanceFrom50 = childTruthScore.Distance(50);
let childWeight = 2 * childTruthScore_distanceFrom50;
let childWeightMultiplier = ReasonScore_CalculateWeightMultiplier(childArgument);
childWeight *= childWeightMultiplier;
let childTruthScore_distanceFrom50_weighted = childTruthScore_distanceFrom50 * AsFraction(childWeight);
let childScore_forAveraging =
childArgument.finalPolarity == Polarity.Supporting
? 50 + childTruthScore_distanceFrom50_weighted
: 50 - childTruthScore_distanceFrom50_weighted;
childScores_forAveraging.push(childScore_forAveraging);
}
return childScores_forAveraging.Average();
}
export function ReasonScore_CalculateWeightMultiplier(node: MapNodeL3) {
Assert(node.type == MapNodeType.Argument, "RS weight-multiplier can only be calculated for an argument<>claim combo -- which is specified by providing its argument node.");
let children = GetNodeChildrenL3(node);
if (children == emptyArray_forLoading || children.Any(a=>a == null)) return 1; // if still loading, return 1
let childArguments = children.filter(a=>a.type == MapNodeType.Argument);
for (let child of childArguments) {
let childChildren = GetNodeChildrenL3(child);
if (childChildren == emptyArray_forLoading || childChildren.Any(a=>a == null)) return 1; // if still loading, return 100
}
// if no child arguments, return 1
if (childArguments.length == 0) return 1;
let childScores_forAveraging = [];
for (let childArgument of childArguments) {
let childClaim = GetNodeChildrenL3(childArgument).filter(a=>a.type == MapNodeType.Claim)[0];
if (childClaim == null) continue;
let childTruthScore = ReasonScore_CalculateTruthScore(childClaim);
let childTruthScore_distanceFrom50 = childTruthScore.Distance(50);
let childWeight = 2 * childTruthScore_distanceFrom50;
let childWeightMultiplier = ReasonScore_CalculateWeightMultiplier(childArgument);
childWeight *= childWeightMultiplier;
let childTruthScore_distanceFrom50_weighted = childTruthScore_distanceFrom50 * AsFraction(childWeight);
let childScore_forAveraging =
childArgument.finalPolarity == Polarity.Supporting
? 1 + (childTruthScore_distanceFrom50_weighted / 50)
: 1 - (childTruthScore_distanceFrom50_weighted / 50);
childScores_forAveraging.push(childScore_forAveraging);
}
return childScores_forAveraging.Average();
}
function AsFraction(valueFrom0To100: number) {
return valueFrom0To100 / 100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment