Пример #1
0
        internal override bool IsUnifiableImpl(FeatureValue other, bool useDefaults, VariableBindings varBindings)
        {
            SimpleFeatureValue otherSfv;

            if (!Dereference(other, out otherSfv))
            {
                return(false);
            }

            if (!IsVariable && !otherSfv.IsVariable)
            {
                if (!Overlaps(false, otherSfv, false))
                {
                    return(false);
                }
            }
            else if (IsVariable && !otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(VariableName, out binding))
                {
                    if (!binding.Overlaps(!Agree, otherSfv, false))
                    {
                        return(false);
                    }
                }
                else
                {
                    varBindings[VariableName] = otherSfv.GetVariableValue(Agree);
                }
            }
            else if (!IsVariable && otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(otherSfv.VariableName, out binding))
                {
                    if (!Overlaps(false, binding, !otherSfv.Agree))
                    {
                        return(false);
                    }
                }
                else
                {
                    varBindings[otherSfv.VariableName] = GetVariableValue(otherSfv.Agree);
                }
            }
            else
            {
                if (VariableName != otherSfv.VariableName || Agree != otherSfv.Agree)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        internal override bool SubtractImpl(FeatureValue other, VariableBindings varBindings, IDictionary <FeatureStruct, ISet <FeatureStruct> > visited)
        {
            SimpleFeatureValue otherSfv;

            if (!Dereference(other, out otherSfv))
            {
                return(true);
            }

            if (!IsVariable && !otherSfv.IsVariable)
            {
                ExceptWith(false, otherSfv, false);
            }
            else if (IsVariable && !otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(VariableName, out binding))
                {
                    UnionWith(false, binding, !Agree);
                    ExceptWith(false, otherSfv, false);
                    VariableName = null;
                }
            }
            else if (!IsVariable && otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(otherSfv.VariableName, out binding))
                {
                    ExceptWith(false, binding, !otherSfv.Agree);
                }
            }
            else
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(VariableName, out binding))
                {
                    UnionWith(false, binding, !Agree);
                    SimpleFeatureValue otherBinding;
                    if (varBindings.TryGetValue(otherSfv.VariableName, out otherBinding))
                    {
                        ExceptWith(false, otherSfv, false);
                    }
                    VariableName = null;
                }
                else if (!varBindings.ContainsVariable(otherSfv.VariableName))
                {
                    return(VariableName != otherSfv.VariableName || Agree != otherSfv.Agree);
                }
            }

            return(IsSatisfiable);
        }
Пример #3
0
        private void ReplaceVariables(VariableBindings varBindings, ISet <FeatureStruct> visited)
        {
            if (visited.Contains(this))
            {
                return;
            }

            visited.Add(this);

            var replacements = new Dictionary <Feature, FeatureValue>();

            foreach (KeyValuePair <Feature, FeatureValue> featVal in _definite)
            {
                FeatureValue value = Dereference(featVal.Value);
                var          sfv   = value as SimpleFeatureValue;
                if (sfv != null)
                {
                    if (sfv.IsVariable)
                    {
                        SimpleFeatureValue binding;
                        if (varBindings.TryGetValue(sfv.VariableName, out binding))
                        {
                            replacements[featVal.Key] = binding.GetVariableValue(sfv.Agree);
                        }
                    }
                }
                else
                {
                    var fs = (FeatureStruct)value;
                    fs.ReplaceVariables(varBindings, visited);
                }
            }

            foreach (KeyValuePair <Feature, FeatureValue> replacement in replacements)
            {
                _definite[replacement.Key] = replacement.Value;
            }
        }
Пример #4
0
        internal override bool UnionImpl(FeatureValue other, VariableBindings varBindings, IDictionary <FeatureStruct, ISet <FeatureStruct> > visited)
        {
            SimpleFeatureValue otherSfv;

            if (!Dereference(other, out otherSfv))
            {
                return(true);
            }

            if (!IsVariable && !otherSfv.IsVariable)
            {
                UnionWith(false, otherSfv, false);
            }
            else if (IsVariable && !otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(VariableName, out binding))
                {
                    UnionWith(false, binding, !Agree);
                    UnionWith(false, otherSfv, false);
                }
                else
                {
                    UnionWith(false, otherSfv, false);
                    varBindings[VariableName] = otherSfv.GetVariableValue(Agree);
                }
                VariableName = null;
            }
            else if (!IsVariable && otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(otherSfv.VariableName, out binding))
                {
                    UnionWith(false, binding, !otherSfv.Agree);
                }
                else
                {
                    varBindings[otherSfv.VariableName] = GetVariableValue(otherSfv.Agree);
                }
            }
            else
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(VariableName, out binding))
                {
                    UnionWith(false, binding, !Agree);
                    SimpleFeatureValue otherBinding;
                    if (varBindings.TryGetValue(otherSfv.VariableName, out otherBinding))
                    {
                        UnionWith(false, otherBinding, !otherSfv.Agree);
                    }
                    VariableName = null;
                }
                else
                {
                    SimpleFeatureValue otherBinding;
                    if (varBindings.TryGetValue(otherSfv.VariableName, out otherBinding))
                    {
                        UnionWith(false, otherBinding, !otherSfv.Agree);
                        VariableName = null;
                    }
                    else
                    {
                        return(VariableName == otherSfv.VariableName && Agree == otherSfv.Agree);
                    }
                }
            }

            return(!IsUninstantiated);
        }
Пример #5
0
        internal override bool DestructiveUnify(FeatureValue other, bool useDefaults, bool preserveInput, IDictionary <FeatureValue, FeatureValue> copies, VariableBindings varBindings)
        {
            SimpleFeatureValue otherSfv;

            if (!Dereference(other, out otherSfv))
            {
                return(false);
            }

            if (this == otherSfv)
            {
                return(true);
            }

            if (!IsVariable && !otherSfv.IsVariable)
            {
                if (!Overlaps(false, otherSfv, false))
                {
                    return(false);
                }
                IntersectWith(false, otherSfv, false);
            }
            else if (IsVariable && !otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(VariableName, out binding))
                {
                    if (!binding.Overlaps(!Agree, otherSfv, false))
                    {
                        return(false);
                    }
                    UnionWith(false, binding, !Agree);
                    IntersectWith(false, otherSfv, false);
                }
                else
                {
                    UnionWith(false, otherSfv, false);
                    varBindings[VariableName] = otherSfv.GetVariableValue(Agree);
                }
                VariableName = null;
            }
            else if (!IsVariable && otherSfv.IsVariable)
            {
                SimpleFeatureValue binding;
                if (varBindings.TryGetValue(otherSfv.VariableName, out binding))
                {
                    if (!Overlaps(false, binding, !otherSfv.Agree))
                    {
                        return(false);
                    }
                    IntersectWith(false, binding, !otherSfv.Agree);
                }
                else
                {
                    varBindings[otherSfv.VariableName] = GetVariableValue(otherSfv.Agree);
                }
            }
            else
            {
                if (VariableName != otherSfv.VariableName || Agree != otherSfv.Agree)
                {
                    return(false);
                }
            }

            if (preserveInput)
            {
                if (copies != null)
                {
                    copies[otherSfv] = this;
                }
            }
            else
            {
                otherSfv.Forward = this;
            }

            return(true);
        }
Пример #6
0
        private void PriorityUnion(FeatureStruct other, VariableBindings varBindings, IDictionary <FeatureValue, FeatureValue> copies)
        {
            other = Dereference(other);

            copies[other] = this;

            foreach (KeyValuePair <Feature, FeatureValue> featVal in _definite)
            {
                FeatureValue thisValue = Dereference(featVal.Value);
                FeatureValue otherValue;
                if (other._definite.TryGetValue(featVal.Key, out otherValue))
                {
                    otherValue = Dereference(otherValue);
                    var otherFS = otherValue as FeatureStruct;
                    if (otherFS != null && !copies.ContainsKey(otherFS))
                    {
                        var thisFS = thisValue as FeatureStruct;
                        if (thisFS != null)
                        {
                            thisFS.PriorityUnion(otherFS, varBindings, copies);
                        }
                    }
                }
            }

            foreach (KeyValuePair <Feature, FeatureValue> featVal in other._definite)
            {
                FeatureValue otherValue = Dereference(featVal.Value);
                FeatureValue thisValue;
                if (_definite.TryGetValue(featVal.Key, out thisValue))
                {
                    otherValue = Dereference(otherValue);
                    var otherFS = otherValue as FeatureStruct;
                    if (otherFS != null)
                    {
                        if (thisValue is FeatureStruct)
                        {
                            FeatureValue reentrant;
                            if (copies.TryGetValue(otherFS, out reentrant))
                            {
                                _definite[featVal.Key] = reentrant;
                            }
                        }
                        else
                        {
                            _definite[featVal.Key] = otherFS.DeepCloneImpl(copies);
                        }
                    }
                    else
                    {
                        var otherSfv = (SimpleFeatureValue)otherValue;
                        SimpleFeatureValue binding;
                        if (otherSfv.IsVariable && varBindings.TryGetValue(otherSfv.VariableName, out binding))
                        {
                            _definite[featVal.Key] = binding.GetVariableValue(otherSfv.Agree);
                        }
                        else
                        {
                            _definite[featVal.Key] = otherSfv.DeepCloneImpl(copies);
                        }
                    }
                }
                else
                {
                    _definite[featVal.Key] = otherValue.DeepCloneImpl(copies);
                }
            }
        }