Skip to content

Fydar/TextPolicy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔓 TextConstraints

TextConstraints is a few simple libraries for producing policies with regard to passwords and text validation written in C#.

Console text policy demo. A command-line password policy validator.

⚖ Text Policies

Password policies are constructed using a fluent interface.

A sample password policy A sample password policy.

Password policies can be extended with arbitrary rules to create more complex password policies that enforce more requirements.

Creating a more complex password policy Creating a more complex password policy.

Password policies can be evaluated quite simply, with a result object which can be evaluated to determine which rules passed and failed within the policy.

Evaluating text against a policy Evaluating text against a policy.

🧪 Creating custom rules

Custom rules can be created by implementing the ITextRule interface.

A custom ITextRule implementation A custom ITextRule implementation.

Rules can then be added to a policy like any other rule.

Using a custom text rule in a policy Using a custom text rule in a policy.

🌲 Word Trees

A word tree is a compact mechanism used to store dictionaries for quick lookups.

This project serilies word trees in a binary format, via the following specificiation

[0..-1] = TreeNode[] : An array of all nodes contained within the tree.

Structure: TreeNode (3 bytes)
  [0..0] = char : The character this node represents. 
  [1..2] = ushort : The amount of proceeding nodes that should be considered a child node of this one. +32768 if the node represents a full word.

All words in the Oxford English Dictionary found here in this tree format compresses down to ~372 KB. This may be quite larger than expected; but this is a search-optimized data structure. Other encodings like Huffman encoding on comma-seperated values will optimize for size more efficiantly.

Once loaded, a word tree can be quickly scanned to see whether a word is contained within a tree; and also list all elements in the tree past a given node.

Finding suggestions in a word tree Finding suggestions in a word tree.

This feature to be able to find words using a given prefix is how a lot of auto-complete tools can be implemented. Below is a console demo of this.

Console word tree demo. A command-line demonstration of word auto-completion.

This implementation of word trees cannot handle a single root letter containing more than 32,768 words.

This implementation of word trees only affords for a single ASCII byte for characters. Unicode is not supported.

To address the issues highlighted above; the data-structure can be increased in size.

📝 License

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Creative Commons License

About

Libraries for evaluating text against predefined policies in C#.

Topics

Resources

License

Stars

Watchers

Forks

Languages