Exemple #1
0
        /// <summary>
        /// <para>
        /// Initializes a new <see cref="FileStorage"/> instance.
        /// </para>
        /// <para></para>
        /// </summary>
        /// <param name="DBFilename">
        /// <para>A db filename.</para>
        /// <para></para>
        /// </param>
        public FileStorage(string DBFilename)
        {
            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);
            var dataMemory     = new FileMappedResizableDirectMemory(DBFilename);

            _disposableLinks   = new UnitedMemoryLinks <TLinkAddress>(dataMemory, UnitedMemoryLinks <UInt64> .DefaultLinksSizeStep, linksConstants, IndexTreeType.Default);
            _synchronizedLinks = new SynchronizedLinks <TLinkAddress>(_disposableLinks);
            var link = _synchronizedLinks.Create();

            link = _synchronizedLinks.Update(link, newSource: link, newTarget: link);
            ushort currentMappingLinkIndex = 1;

            Any                       = _synchronizedLinks.Constants.Any;
            _meaningRoot              = GetOrCreateMeaningRoot(currentMappingLinkIndex++);
            _unicodeSymbolMarker      = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _unicodeSequenceMarker    = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _setMarker                = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _fileMarker               = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _addressToNumberConverter = new AddressToRawNumberConverter <TLinkAddress>();
            _numberToAddressConverter = new RawNumberToAddressConverter <TLinkAddress>();
            var balancedVariantConverter        = new BalancedVariantConverter <TLinkAddress>(_synchronizedLinks);
            var unicodeSymbolCriterionMatcher   = new TargetMatcher <TLinkAddress>(_synchronizedLinks, _unicodeSymbolMarker);
            var unicodeSequenceCriterionMatcher = new TargetMatcher <TLinkAddress>(_synchronizedLinks, _unicodeSequenceMarker);
            var charToUnicodeSymbolConverter    = new CharToUnicodeSymbolConverter <TLinkAddress>(_synchronizedLinks, _addressToNumberConverter, _unicodeSymbolMarker);
            var unicodeSymbolToCharConverter    = new UnicodeSymbolToCharConverter <TLinkAddress>(_synchronizedLinks, _numberToAddressConverter, unicodeSymbolCriterionMatcher);
            var sequenceWalker = new RightSequenceWalker <TLinkAddress>(_synchronizedLinks, new DefaultStack <TLinkAddress>(), unicodeSymbolCriterionMatcher.IsMatched);

            _stringToUnicodeSequenceConverter = new CachingConverterDecorator <string, TLinkAddress>(new StringToUnicodeSequenceConverter <TLinkAddress>(_synchronizedLinks, charToUnicodeSymbolConverter, balancedVariantConverter, _unicodeSequenceMarker));
            _unicodeSequenceToStringConverter = new CachingConverterDecorator <TLinkAddress, string>(new UnicodeSequenceToStringConverter <TLinkAddress>(_synchronizedLinks, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter));
        }
Exemple #2
0
 public static void CharAndRawNumberUnicodeSymbolConvertersTest()
 {
     using (var scope = new Scope <Types <HeapResizableDirectMemory, UnitedMemoryLinks <ulong> > >())
     {
         var links       = scope.Use <ILinks <ulong> >();
         var meaningRoot = links.CreatePoint();
         var addressToRawNumberConverter = new AddressToRawNumberConverter <ulong>();
         var rawNumberToAddressConverter = new RawNumberToAddressConverter <ulong>();
         TestCharAndUnicodeSymbolConverters(links, meaningRoot, addressToRawNumberConverter, rawNumberToAddressConverter);
     }
 }
Exemple #3
0
        public DoubletsDbContext(string dataDBFilename, string indexDBFilename)
        {
            var dataMemory  = new FileMappedResizableDirectMemory(dataDBFilename);
            var indexMemory = new FileMappedResizableDirectMemory(indexDBFilename);

            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);

            // Init the links storage
            _disposableLinks = new UInt32SplitMemoryLinks(dataMemory, indexMemory, UInt32SplitMemoryLinks.DefaultLinksSizeStep, linksConstants); // Low-level logic
            _links           = new UInt32Links(_disposableLinks);                                                                                // Main logic in the combined decorator

            // Set up constant links (markers, aka mapped links)
            TLinkAddress currentMappingLinkIndex = 1;

            _meaningRoot                       = GetOrCreateMeaningRoot(currentMappingLinkIndex++);
            _unicodeSymbolMarker               = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _unicodeSequenceMarker             = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _titlePropertyMarker               = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _contentPropertyMarker             = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _publicationDateTimePropertyMarker = GetOrCreateNextMapping(currentMappingLinkIndex++);
            _blogPostMarker                    = GetOrCreateNextMapping(currentMappingLinkIndex++);

            // Create properties operator that is able to control reading and writing properties for any link (object)
            _defaultLinkPropertyOperator = new PropertiesOperator <TLinkAddress>(_links);

            // Create converters that are able to convert link's address (UInt64 value) to a raw number represented with another UInt64 value and back
            _numberToAddressConverter = new RawNumberToAddressConverter <TLinkAddress>();
            _addressToNumberConverter = new AddressToRawNumberConverter <TLinkAddress>();

            // Create converters for dates
            _longRawNumberToDateTimeConverter = new LongRawNumberSequenceToDateTimeConverter <TLinkAddress>(new LongRawNumberSequenceToNumberConverter <TLinkAddress, long>(_links, _numberToAddressConverter));
            _dateTimeToLongRawNumberConverter = new DateTimeToLongRawNumberSequenceConverter <TLinkAddress>(new NumberToLongRawNumberSequenceConverter <long, TLinkAddress>(_links, _addressToNumberConverter));

            // Create converters that are able to convert string to unicode sequence stored as link and back
            var balancedVariantConverter        = new BalancedVariantConverter <TLinkAddress>(_links);
            var unicodeSymbolCriterionMatcher   = new TargetMatcher <TLinkAddress>(_links, _unicodeSymbolMarker);
            var unicodeSequenceCriterionMatcher = new TargetMatcher <TLinkAddress>(_links, _unicodeSequenceMarker);
            var charToUnicodeSymbolConverter    = new CharToUnicodeSymbolConverter <TLinkAddress>(_links, _addressToNumberConverter, _unicodeSymbolMarker);
            var unicodeSymbolToCharConverter    = new UnicodeSymbolToCharConverter <TLinkAddress>(_links, _numberToAddressConverter, unicodeSymbolCriterionMatcher);
            var sequenceWalker = new RightSequenceWalker <TLinkAddress>(_links, new DefaultStack <TLinkAddress>(), unicodeSymbolCriterionMatcher.IsMatched);

            _stringToUnicodeSequenceConverter = new CachingConverterDecorator <string, TLinkAddress>(new StringToUnicodeSequenceConverter <TLinkAddress>(_links, charToUnicodeSymbolConverter, balancedVariantConverter, _unicodeSequenceMarker));
            _unicodeSequenceToStringConverter = new CachingConverterDecorator <TLinkAddress, string>(new UnicodeSequenceToStringConverter <TLinkAddress>(_links, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter));
        }
Exemple #4
0
        public Patterns(string sourceImagePath)
        {
            _sourceImagePath = Path.GetFullPath(sourceImagePath);
            _image           = new MagickImage(sourceImagePath);
            _pixels          = _image.GetPixels();
            _linksPath       = Path.ChangeExtension(_sourceImagePath, ".links");
            var memory    = new HeapResizableDirectMemory(); //new FileMappedResizableDirectMemory(_linksPath);
            var constants = new LinksConstants <ulong>(enableExternalReferencesSupport: true);

            _links = new UInt64Links(new UInt64UnitedMemoryLinks(memory, UInt64UnitedMemoryLinks.DefaultLinksSizeStep, constants, Platform.Data.Doublets.Memory.IndexTreeType.SizedAndThreadedAVLBalancedTree));
            _addressToRawNumberConverter         = new AddressToRawNumberConverter <ulong>();
            _rawNumberToAddressConverter         = new RawNumberToAddressConverter <ulong>();
            _totalSequenceSymbolFrequencyCounter = new TotalSequenceSymbolFrequencyCounter <ulong>(_links);
            _linkFrequenciesCache = new LinkFrequenciesCache <ulong>(_links, _totalSequenceSymbolFrequencyCounter);
            _index = new CachedFrequencyIncrementingSequenceIndex <ulong>(_linkFrequenciesCache);
            _linkToItsFrequencyNumberConverter        = new FrequenciesCacheBasedLinkToItsFrequencyNumberConverter <ulong>(_linkFrequenciesCache);
            _sequenceToItsLocalElementLevelsConverter = new SequenceToItsLocalElementLevelsConverter <ulong>(_links, _linkToItsFrequencyNumberConverter);
            _optimalVariantConverter = new OptimalVariantConverter <ulong>(_links, _sequenceToItsLocalElementLevelsConverter);
        }
Exemple #5
0
        public PlatformDataBase(string indexFileName, string dataFileName)
        {
            this.indexFileName = indexFileName;
            this.dataFileName  = dataFileName;

            var dataMemory  = new FileMappedResizableDirectMemory(this.dataFileName);
            var indexMemory = new FileMappedResizableDirectMemory(this.indexFileName);

            var linksConstants = new LinksConstants <TLinkAddress>(enableExternalReferencesSupport: true);

            // Init the links storage
            this._disposableLinks = new UInt32SplitMemoryLinks(dataMemory, indexMemory, UInt32SplitMemoryLinks.DefaultLinksSizeStep, linksConstants); // Low-level logic
            this.links            = new UInt32Links(_disposableLinks);                                                                                // Main logic in the combined decorator

            // Set up constant links (markers, aka mapped links)
            TLinkAddress currentMappingLinkIndex = 1;

            this._meaningRoot           = GerOrCreateMeaningRoot(currentMappingLinkIndex++);
            this._unicodeSymbolMarker   = GetOrCreateNextMapping(currentMappingLinkIndex++);
            this._unicodeSequenceMarker = GetOrCreateNextMapping(currentMappingLinkIndex++);
            this._bookMarker            = GetOrCreateNextMapping(currentMappingLinkIndex++);
            // Create converters that are able to convert link's address (UInt64 value) to a raw number represented with another UInt64 value and back
            this._numberToAddressConverter = new RawNumberToAddressConverter <TLinkAddress>();
            this._addressToNumberConverter = new AddressToRawNumberConverter <TLinkAddress>();

            // Create converters that are able to convert string to unicode sequence stored as link and back
            var balancedVariantConverter        = new BalancedVariantConverter <TLinkAddress>(links);
            var unicodeSymbolCriterionMatcher   = new TargetMatcher <TLinkAddress>(links, _unicodeSymbolMarker);
            var unicodeSequenceCriterionMatcher = new TargetMatcher <TLinkAddress>(links, _unicodeSequenceMarker);
            var charToUnicodeSymbolConverter    = new CharToUnicodeSymbolConverter <TLinkAddress>(links, _addressToNumberConverter, _unicodeSymbolMarker);
            var unicodeSymbolToCharConverter    = new UnicodeSymbolToCharConverter <TLinkAddress>(links, _numberToAddressConverter, unicodeSymbolCriterionMatcher);
            var sequenceWalker = new RightSequenceWalker <TLinkAddress>(links, new DefaultStack <TLinkAddress>(), unicodeSymbolCriterionMatcher.IsMatched);

            this._stringToUnicodeSequenceConverter = new CachingConverterDecorator <string, TLinkAddress>(new StringToUnicodeSequenceConverter <TLinkAddress>(links, charToUnicodeSymbolConverter, balancedVariantConverter, _unicodeSequenceMarker));
            this._unicodeSequenceToStringConverter = new CachingConverterDecorator <TLinkAddress, string>(new UnicodeSequenceToStringConverter <TLinkAddress>(links, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter));
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var constants = new LinksConstants <ulong>((1, long.MaxValue), (long.MaxValue + 1UL, ulong.MaxValue));

            using var memory = new UInt64ResizableDirectMemoryLinks(new HeapResizableDirectMemory());
            var links = memory.DecorateWithAutomaticUniquenessAndUsagesResolution();

            var addressToRawNumberConverter = new AddressToRawNumberConverter <ulong>();
            var rawNumberToAddressConverter = new RawNumberToAddressConverter <ulong>();

            var root = links.GetOrCreate(1UL, 1UL);
            var unicodeSymbolMarker = links.GetOrCreate(root, addressToRawNumberConverter.Convert(1));
            var patternRootMarker   = links.GetOrCreate(root, addressToRawNumberConverter.Convert(2));

            var charToUnicodeSymbolConverter = new Platform.Data.Doublets.Unicode.CharToUnicodeSymbolConverter <ulong>(links, addressToRawNumberConverter, unicodeSymbolMarker);

            var strings = new[] { "href", "target", "rel", "media", "hreflang", "type", "sizes", "content", "name", "src", "charset", "text", "cite", "ping", "alt", "sandbox", "width", "height", "data", "value", "poster", "coords", "shape", "scope", "action", "enctype", "method", "accept", "max", "min", "pattern", "placeholder", "step", "label", "wrap", "icon", "radiogroup" };

            var patternRootMarkerArray = new[] { patternRootMarker };

            var sequences = strings.Select((s, i) => patternRootMarkerArray.Concat(BuildSequence(s, i, links, addressToRawNumberConverter, charToUnicodeSymbolConverter)).Concat(patternRootMarkerArray).ToArray()).ToArray();

            var index = new SequenceIndex <ulong>(links);

            var any       = links.Constants.Any;
            var @continue = links.Constants.Continue;

            for (int i = 0; i < sequences.Length; i++)
            {
                index.Add(sequences[i]);
            }

            var chars = new Dictionary <ulong, char>();

            links.Each(linkParts =>
            {
                var link = new UInt64Link(linkParts);

                if (link.Target == unicodeSymbolMarker)
                {
                    var symbol = (char)rawNumberToAddressConverter.Convert(link.Source);
                    chars.Add(link.Index, symbol);
                    Console.WriteLine($"({link.Index}: '{symbol}'->{link.Target})");
                }
                else
                {
                    var sourceString = LinkToString(links, constants, link.Source, chars, rawNumberToAddressConverter);
                    var targetString = LinkToString(links, constants, link.Target, chars, rawNumberToAddressConverter);
                    Console.WriteLine($"({link.Index}: {sourceString}->{targetString})");
                }
                return(@continue);
            }, new UInt64Link(any, any, any));

            StringBuilder sb = new StringBuilder();

            sb.Append('^');
            AppendPattern(links, constants, patternRootMarker, patternRootMarker, chars, any, @continue, sb, 0UL, rawNumberToAddressConverter);
            sb.Append('$');
            var result = sb.ToString();

            var simplificationRegex = new Regex(@"\(([a-z\?]*)\)", RegexOptions.Compiled);

            while (simplificationRegex.IsMatch(result))
            {
                result = simplificationRegex.Replace(result, "$1");
            }

            // (|t)
            // t?
            var simplificationRegex2 = new Regex(@"\(\|([a-z])\)", RegexOptions.Compiled);

            while (simplificationRegex2.IsMatch(result))
            {
                result = simplificationRegex2.Replace(result, "$1?");
            }

            // Repeat
            while (simplificationRegex.IsMatch(result))
            {
                result = simplificationRegex.Replace(result, "$1");
            }

            var regex = new Regex(result);

            for (int i = 0; i < strings.Length; i++)
            {
                if (!regex.IsMatch(strings[i]))
                {
                    Console.WriteLine($"Error: {strings[i]} does not match the pattern.");
                }
            }

            Console.WriteLine(result);

            Console.WriteLine(links.Count());
            Console.WriteLine("Hello World!");
        }
Exemple #7
0
        private static void AppendPattern(ILinks <ulong> links, LinksConstants <ulong> constants, ulong start, ulong patternMarker, Dictionary <ulong, char> chars, ulong any, ulong @continue, StringBuilder sb, ulong initialPosition, RawNumberToAddressConverter <ulong> rawNumberToAddressConverter)
        {
            sb.Append('(');
            var alternatives = 0;

            links.Each(linkParts =>
            {
                var link = new UInt64Link(linkParts);
                if (patternMarker == link.Target)
                {
                    if (alternatives > 0)
                    {
                        sb.Append('|');
                    }
                    alternatives++;
                }
                else if (!constants.IsExternalReference(link.Target))
                {
                    var charPosition = new UInt64Link(links.GetLink(link.Target));
                    if (constants.IsExternalReference(charPosition.Source) && chars.TryGetValue(charPosition.Target, out char targetSymbol))
                    {
                        var position = rawNumberToAddressConverter.Convert(charPosition.Source) - 10;
                        if (position == initialPosition)
                        {
                            if (alternatives > 0)
                            {
                                sb.Append('|');
                            }
                            sb.Append(targetSymbol);
                            AppendPattern(links, constants, link.Target, patternMarker, chars, any, @continue, sb, initialPosition + 1, rawNumberToAddressConverter);
                            alternatives++;
                        }
                    }
                }
                return(@continue);
            }, new UInt64Link(any, start, any));
            sb.Append(')');
        }
Exemple #8
0
 private static string LinkToString(ILinks <ulong> links, LinksConstants <ulong> constants, ulong linkAddress, Dictionary <ulong, char> chars, RawNumberToAddressConverter <ulong> rawNumberToAddressConverter)
 {
     if (chars.TryGetValue(linkAddress, out char @char))
     {
         return($"'{@char.ToString()}'");
     }
     else if (constants.IsExternalReference(linkAddress))
     {
         return(rawNumberToAddressConverter.Convert(linkAddress).ToString());
     }
     else
     {
         var link = new UInt64Link(links.GetLink(linkAddress));
         if (constants.IsExternalReference(link.Source) && chars.TryGetValue(link.Target, out char targetChar))
         {
             return($"[{rawNumberToAddressConverter.Convert(link.Source)}]'{targetChar}'");
         }
         else
         {
             return(linkAddress.ToString());
         }
     }
 }