Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Common / Utils / Boolean / Sentence.cs / 3 / Sentence.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; namespace System.Data.Common.Utils.Boolean { ////// Abstract base class for nodes in normal form expressions, e.g. Conjunctive Normal Form /// sentences. /// ///Type of expression leaf term identifiers. internal abstract class NormalFormNode{ private readonly BoolExpr _expr; /// /// Initialize a new normal form node representing the given expression. Caller must /// ensure the expression is logically equivalent to the node. /// /// Expression logically equivalent to this node. protected NormalFormNode(BoolExprexpr) { _expr = expr.Simplify(); } /// /// Gets an expression that is logically equivalent to this node. /// internal BoolExprExpr { get { return _expr; } } /// /// Utility method for delegation that return the expression corresponding to a given /// normal form node. /// ///Type of node /// Node to examine. ///Equivalent Boolean expression for the given node. protected static BoolExprExprSelector (T_NormalFormNode node) where T_NormalFormNode : NormalFormNode { return node._expr; } } /// /// Abstract base class for normal form sentences (CNF and DNF) /// ///Type of expression leaf term identifiers. ///Type of clauses in the sentence. internal abstract class Sentence: NormalFormNode where T_Clause : Clause , IEquatable { private readonly Set _clauses; /// /// Initialize a sentence given the appropriate sentence clauses. Produces /// an equivalent expression by composing the clause expressions using /// the given tree type. /// /// Sentence clauses /// Tree type for sentence (and generated expression) protected Sentence(Setclauses, ExprType treeType) : base(ConvertClausesToExpr(clauses, treeType)) { _clauses = clauses.AsReadOnly(); } // Produces an expression equivalent to the given clauses by composing the clause // expressions using the given tree type. private static BoolExpr ConvertClausesToExpr(Set clauses, ExprType treeType) { bool isAnd = ExprType.And == treeType; Debug.Assert(isAnd || ExprType.Or == treeType); IEnumerable > clauseExpressions = clauses.Select(new Func >(ExprSelector)); if (isAnd) { return new AndExpr (clauseExpressions); } else { return new OrExpr (clauseExpressions); } } public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append("Sentence{"); builder.Append(_clauses); return builder.Append("}").ToString(); } } /// /// Represents a sentence in disjunctive normal form, e.g.: /// /// Clause1 + Clause2 . ... /// /// Where each DNF clause is of the form: /// /// Literal1 . Literal2 . ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of expression leaf term identifiers. internal sealed class DnfSentence: Sentence > { // Initializes a new DNF sentence given its clauses. internal DnfSentence(Set > clauses) : base(clauses, ExprType.Or) { } } /// /// Represents a sentence in conjunctive normal form, e.g.: /// /// Clause1 . Clause2 . ... /// /// Where each DNF clause is of the form: /// /// Literal1 + Literal2 + ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of expression leaf term identifiers. internal sealed class CnfSentence: Sentence > { // Initializes a new CNF sentence given its clauses. internal CnfSentence(Set > clauses) : base(clauses, ExprType.And) { } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; namespace System.Data.Common.Utils.Boolean { ////// Abstract base class for nodes in normal form expressions, e.g. Conjunctive Normal Form /// sentences. /// ///Type of expression leaf term identifiers. internal abstract class NormalFormNode{ private readonly BoolExpr _expr; /// /// Initialize a new normal form node representing the given expression. Caller must /// ensure the expression is logically equivalent to the node. /// /// Expression logically equivalent to this node. protected NormalFormNode(BoolExprexpr) { _expr = expr.Simplify(); } /// /// Gets an expression that is logically equivalent to this node. /// internal BoolExprExpr { get { return _expr; } } /// /// Utility method for delegation that return the expression corresponding to a given /// normal form node. /// ///Type of node /// Node to examine. ///Equivalent Boolean expression for the given node. protected static BoolExprExprSelector (T_NormalFormNode node) where T_NormalFormNode : NormalFormNode { return node._expr; } } /// /// Abstract base class for normal form sentences (CNF and DNF) /// ///Type of expression leaf term identifiers. ///Type of clauses in the sentence. internal abstract class Sentence: NormalFormNode where T_Clause : Clause , IEquatable { private readonly Set _clauses; /// /// Initialize a sentence given the appropriate sentence clauses. Produces /// an equivalent expression by composing the clause expressions using /// the given tree type. /// /// Sentence clauses /// Tree type for sentence (and generated expression) protected Sentence(Setclauses, ExprType treeType) : base(ConvertClausesToExpr(clauses, treeType)) { _clauses = clauses.AsReadOnly(); } // Produces an expression equivalent to the given clauses by composing the clause // expressions using the given tree type. private static BoolExpr ConvertClausesToExpr(Set clauses, ExprType treeType) { bool isAnd = ExprType.And == treeType; Debug.Assert(isAnd || ExprType.Or == treeType); IEnumerable > clauseExpressions = clauses.Select(new Func >(ExprSelector)); if (isAnd) { return new AndExpr (clauseExpressions); } else { return new OrExpr (clauseExpressions); } } public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append("Sentence{"); builder.Append(_clauses); return builder.Append("}").ToString(); } } /// /// Represents a sentence in disjunctive normal form, e.g.: /// /// Clause1 + Clause2 . ... /// /// Where each DNF clause is of the form: /// /// Literal1 . Literal2 . ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of expression leaf term identifiers. internal sealed class DnfSentence: Sentence > { // Initializes a new DNF sentence given its clauses. internal DnfSentence(Set > clauses) : base(clauses, ExprType.Or) { } } /// /// Represents a sentence in conjunctive normal form, e.g.: /// /// Clause1 . Clause2 . ... /// /// Where each DNF clause is of the form: /// /// Literal1 + Literal2 + ... /// /// Each literal is of the form: /// /// Term /// /// or /// /// !Term /// ///Type of expression leaf term identifiers. internal sealed class CnfSentence: Sentence > { // Initializes a new CNF sentence given its clauses. internal CnfSentence(Set > clauses) : base(clauses, ExprType.And) { } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlEnumAttribute.cs
- ConditionBrowserDialog.cs
- SR.cs
- SrgsToken.cs
- DataRowComparer.cs
- CodeDomLocalizationProvider.cs
- BeginStoryboard.cs
- hwndwrapper.cs
- XmlDataSource.cs
- PrintDocument.cs
- RenderTargetBitmap.cs
- Walker.cs
- QueryParameter.cs
- SiteMapSection.cs
- ProcessHostConfigUtils.cs
- SmiGettersStream.cs
- DecoderNLS.cs
- SafeNativeMethods.cs
- SafeFileHandle.cs
- ValidatorAttribute.cs
- ContentElement.cs
- CallbackException.cs
- WebServiceHandlerFactory.cs
- Select.cs
- ProfileManager.cs
- CqlParserHelpers.cs
- SystemIcmpV4Statistics.cs
- WSHttpBinding.cs
- HwndHostAutomationPeer.cs
- EntityDataSourceDesigner.cs
- XmlSchemaAnyAttribute.cs
- XPathLexer.cs
- TreeViewEvent.cs
- ProtocolReflector.cs
- AsymmetricKeyExchangeFormatter.cs
- SelectorItemAutomationPeer.cs
- ConfigXmlAttribute.cs
- MailBnfHelper.cs
- EmptyQuery.cs
- AuthorizationRuleCollection.cs
- CharKeyFrameCollection.cs
- DeferredElementTreeState.cs
- CodeChecksumPragma.cs
- System.Data.OracleClient_BID.cs
- Matrix3D.cs
- IntegerCollectionEditor.cs
- SystemWebSectionGroup.cs
- FileDetails.cs
- AppDomain.cs
- GridViewDeletedEventArgs.cs
- HttpResponseHeader.cs
- RecognizedPhrase.cs
- RestHandler.cs
- TypeConverterHelper.cs
- AnonymousIdentificationModule.cs
- SevenBitStream.cs
- _Rfc2616CacheValidators.cs
- MethodCallTranslator.cs
- CodeSubDirectory.cs
- DBAsyncResult.cs
- Helper.cs
- StrokeNode.cs
- DataServiceRequestException.cs
- Graphics.cs
- DataControlReferenceCollection.cs
- FixUpCollection.cs
- ParameterDataSourceExpression.cs
- HttpWebRequest.cs
- FolderBrowserDialogDesigner.cs
- AutomationProperties.cs
- XmlSchemaInferenceException.cs
- HtmlValidatorAdapter.cs
- DrawingImage.cs
- ExpressionList.cs
- HttpModuleActionCollection.cs
- SignatureResourcePool.cs
- ResXFileRef.cs
- WeakRefEnumerator.cs
- XmlFormatExtensionAttribute.cs
- StrongNameMembershipCondition.cs
- GridViewColumn.cs
- SoapServerMessage.cs
- storagemappingitemcollection.viewdictionary.cs
- PageContent.cs
- ToolStripRenderer.cs
- DataObject.cs
- HwndSubclass.cs
- MessageEventSubscriptionService.cs
- DataStreams.cs
- TreeViewHitTestInfo.cs
- ToolStripItemCollection.cs
- ObsoleteAttribute.cs
- RecordsAffectedEventArgs.cs
- GeneralTransform2DTo3D.cs
- mediaclock.cs
- TextDecorationUnitValidation.cs
- WindowAutomationPeer.cs
- XamlInt32CollectionSerializer.cs
- Membership.cs
- ResXFileRef.cs