public static RefererOrInterval makeReferer(TermOrCompoundTermOrVariableReferer referer) { RefererOrInterval result = new RefererOrInterval(); result.isInterval = false; result.referer = referer; return(result); }
public static TermOrCompoundTermOrVariableReferer makeDependentVariable(int value) { int BITMAKSFORID = bitmaskForBits(NUMBEROFBITSFORID); Debug.Assert((value & (~BITMAKSFORID)) == 0); TermOrCompoundTermOrVariableReferer result = new TermOrCompoundTermOrVariableReferer(); result.encoding = value | (1 << (int)EnumSpecialMaskBits.DEPENDENTVAR); return(result); }
public static TermOrCompoundTermOrVariableReferer makeNonatomic(int value) { int BITMAKSFORID = bitmaskForBits(NUMBEROFBITSFORID); Debug.Assert((value & (~BITMAKSFORID)) == 0); TermOrCompoundTermOrVariableReferer result = new TermOrCompoundTermOrVariableReferer(); result.encoding = value; return(result); }
internal Compound translateToCompoundChecked(TermOrCompoundTermOrVariableReferer taskTerm) { Ensure.ensure(!taskTerm.isAtomic); Compound compound; try { compound = termRefererIdToCompound[taskTerm.getTerm]; } catch (KeyNotFoundException) { // should never happen throw new Exception("Key not found"); } return(compound); }
internal string getDebugStringByTermReferer(TermOrCompoundTermOrVariableReferer termReferer) { if (termReferer.isVariable) { return("var"); // TODO< a real debug string > } else if (termReferer.isAtomic) { return(termOrCompoundTermOrVariableRefererIdToHumanReadableName[termReferer.getAtomicOrTerm]); } else if (!termReferer.isSpecial) { // if the referer is not a compound return(accessCompoundByIndex(translateCompoundIdToCompoundIndex((ulong)termReferer.getAtomicOrTerm)).getDebugStringRecursive(this)); } else { throw new Exception("Term referer is not a variable or not special, not handled, is an internal error"); } }
internal uint getTermComplexityOfAndByTermReferer(TermOrCompoundTermOrVariableReferer termReferer) { if (termReferer.isVariable) { return(1); } else if (termReferer.isAtomic) { return(1); } else if (!termReferer.isSpecial) { // if the referer is not a compound return(accessCompoundByIndex(translateCompoundIdToCompoundIndex((ulong)termReferer.getAtomicOrTerm)).termComplexity); } else { throw new Exception("Term referer is not a variable or not special, not handled, is an internal error"); } }
public CompoundIndex makeInheritance(string a, string b) { int termOrCompoundTermOrVariableRefererIdOfA, termOrCompoundTermOrVariableRefererIdOfB; TermTupleIndex termTupleIndexOfA = compoundAndTermContext.returnIndexOfTermTupleForHumanReadableTermNameOrCreate(a, out termOrCompoundTermOrVariableRefererIdOfA); TermTupleIndex termTupleIndexOfB = compoundAndTermContext.returnIndexOfTermTupleForHumanReadableTermNameOrCreate(b, out termOrCompoundTermOrVariableRefererIdOfB); var compoundReferers = new TermOrCompoundTermOrVariableReferer[] { compoundAndTermContext.accessTermTupleByIndex(termTupleIndexOfA).refererOrIntervals[0].referer, compoundAndTermContext.accessTermTupleByIndex(termTupleIndexOfB).refererOrIntervals[0].referer, }; TermTupleIndex termTupleIndex; if (compoundAndTermContext.existTermTuple(compoundReferers)) { termTupleIndex = compoundAndTermContext.getTermTupleIndexByReferers(compoundReferers); } else { termTupleIndex = compoundAndTermContext.addTermTupleByReferers(compoundReferers); } // create compound Compound.MakeParameters makeParameters = new Compound.MakeParameters(); makeParameters.flagsOfCopula = FlagsOfCopula.makeInheritance(); makeParameters.termComplexity = 3; makeParameters.termTupleIndex = termTupleIndex; makeParameters.thisTermReferer = TermOrCompoundTermOrVariableReferer.makeNonatomic(compoundAndTermContext.TermOrCompoundTermOrVariableRefererCounter); compoundAndTermContext.TermOrCompoundTermOrVariableRefererCounter++; Compound compound = compoundAndTermContext.createCompound(makeParameters); CompoundIndex compoundIndex = compoundAndTermContext.addCompound(compound); return(compoundIndex); }
public static IList <ClassicalTermLink> prepareComponentLinks(CompoundAndTermContext compoundAndTermContext, TermOrCompoundTermOrVariableReferer term, ClassicalTermLink.EnumType type) { // see https://github.com/opennars/opennars/blob/4515f1d8e191a1f097859decc65153287d5979c5/nars_core/nars/language/Terms.java#L404 IList <ClassicalTermLink> componentLinks = new List <ClassicalTermLink>(); // doesn't go down a level because the Concept already does this for us Compound compoundOfTerm = compoundAndTermContext.translateTermOfCompoundToCompound(term); for (int componentIndex = 0; componentIndex < compoundOfTerm.getComponentLength(compoundAndTermContext); componentIndex++) { RefererOrInterval refererOfInterval = compoundOfTerm.getComponentByIndex(compoundAndTermContext, (uint)componentIndex); Debug.Assert(!refererOfInterval.isInterval); TermOrCompoundTermOrVariableReferer refered = refererOfInterval.referer; componentLinks.Add(new ClassicalTermLink(refered, type, (uint)componentIndex)); } // TODO< other link types > return(componentLinks); }
public static bool isSameWithId(TermOrCompoundTermOrVariableReferer a, TermOrCompoundTermOrVariableReferer b) { return(isSameWithoutId(a, b) && a.maskOutId == b.maskOutId); }
public static bool isSameWithoutId(TermOrCompoundTermOrVariableReferer a, TermOrCompoundTermOrVariableReferer b) { return(a.maskedOutFlags == b.maskedOutFlags); }
internal Compound translateTermOfCompoundToCompound(TermOrCompoundTermOrVariableReferer term) { Debug.Assert(termRefererIdToCompound[term.getMaskedOutId].thisTermReferer.getTerm == term.getTerm); // must be equal else we have an internal consistency problem return(termRefererIdToCompound[term.getMaskedOutId]); }
// returns the index of the term internal TermTupleIndex translateTermOfCompoundToIndex(TermOrCompoundTermOrVariableReferer term) { return(translateTermOfCompoundToCompound(term).termTupleIndex); }
internal TermTupleIndex returnIndexOfTermTupleForHumanReadableTermNameOrCreate(string name, out int termOrCompoundTermOrVariableRefererId) { bool nameIsPresentInHumanReadableNames = termNamesByhumanReadableName.ContainsKey(name); if (nameIsPresentInHumanReadableNames) { termOrCompoundTermOrVariableRefererId = termTuples[(int)termNamesByhumanReadableName[name].index].refererOrIntervals[0].referer.getAtomic; return(termNamesByhumanReadableName[name]); } // else here termOrCompoundTermOrVariableRefererId = TermOrCompoundTermOrVariableRefererCounter; TermOrCompoundTermOrVariableRefererCounter++; TermTuple termTuple = TermTuple.makeByReferers(new TermOrCompoundTermOrVariableReferer[] { TermOrCompoundTermOrVariableReferer.makeAtomic(termOrCompoundTermOrVariableRefererId) }); TermTupleIndex index = TermTupleIndex.make((ulong)termTuples.Count); termTuples.Add(termTuple); termNamesByhumanReadableName[name] = index; termOrCompoundTermOrVariableRefererIdToHumanReadableName[termOrCompoundTermOrVariableRefererId] = name; return(index); }