Exemple #1
0
        public void Test()
        {
            char separator = '/';
            PrefixCollection <Object> pc = new PrefixCollection <Object>(separator);

            StringBuilder buffy = new StringBuilder(32);

            for (int i = 0; i < TEST_ADD.Length; i++)
            {
                //			println(TEST[i].directoryString());
                PrefixPhrase <Object> pp = pc.Add(TEST_ADD[i]);
                buffy.Clear();
                pp.ToStringBuilder(buffy, separator);
                Console.WriteLine(buffy);
            }
            Console.WriteLine("\n");

            for (int i = 0; i < TEST_MATCH.Length; i++)
            {
                ParsedUri purl = TEST_MATCH[i];

                Console.WriteLine(purl.ToString() + "\t" + pc.Match(purl));
            }
            Console.WriteLine("\n");

            foreach (String phrase in pc.Values())
            {
                Console.WriteLine(phrase);
            }
        }
Exemple #2
0
        /// <summary>
        ///  Get MetaMetadata. First, try matching by url_base. If this fails, including if the attribute is
        ///  null, then try by url_prefix. If this fails, including if the attribute is null, then try by
        ///  url_pattern (regular expression).
        ///  <p/>
        /// If that lookup fails, then lookup by tag name, to acquire the default.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public MetaMetadata GetDocumentMM(ParsedUri uri, String tagName = DocumentParserTagNames.DocumentTag)
        {
            MetaMetadata result = null;

            if (uri != null)
            {
                if (!uri.IsFile)
                {
                    //String noAnchorNoQueryPageString = uri.GetLeftPart(UriPartial.Path);
                    String noAnchorNoQueryPageString = FundamentalPlatformSpecifics.Get().GetUriLeftPart(uri);

                    _documentRepositoryByUrlStripped.TryGetValue(noAnchorNoQueryPageString, out result);

                    if (result == null)
                    {
                        //Check to see if the url prefix is actually a url-path tree.
                        //TODO: For url-path-tree cases, we should just generate a regex to handle those cases.
                        PrefixPhrase <MetaMetadata> matchingPrefix = urlPrefixCollection.getMatchingPrefix(uri);
                        if (matchingPrefix != null)
                        {
                            result = matchingPrefix.MappedObject;
                        }
                    }

                    if (result == null)
                    {
                        String domain = uri.Domain;
                        if (domain != null)
                        {
                            List <RepositoryPatternEntry> entries = null;
                            _documentRepositoryByPattern.TryGetValue(domain, out entries);

                            if (entries != null)
                            {
                                foreach (RepositoryPatternEntry entry in entries)
                                {
                                    Match matcher = entry.Pattern.Match(uri.ToString());
                                    if (matcher.Success)
                                    {
                                        result = entry.MetaMetadata;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                // be careful of the order! suffix before domain

                if (result == null)
                {
                    String suffix = uri.Suffix;

                    if (suffix != null)
                    {
                        result = GetMMBySuffix(suffix);
                    }
                }
                if (result == null)
                {
                    String domain = uri.Domain;
                    _documentRepositoryByDomain.TryGetValue(domain, out result);

                    if (result != null)
                    {
                        Debug.WriteLine("Matched by domain = " + domain + "\t" + result);
                    }
                }
            }
            if (result == null)
            {
                result = GetMMByName(tagName);
            }

            return(result);
        }
Exemple #3
0
        /**
         * Initializes HashMaps for MetaMetadata selectors by URL or pattern. Uses the ClippableDocument and Document
         * base classes to ensure that maps are only filled with appropriate matching MetaMetadata.
         */

        public void InitializeLocationBasedMaps()
        {
            foreach (MetaMetadata metaMetadata in _repositoryByName.Values)
            {
                // metaMetadata.inheritMetaMetadata(this);

                Type metadataClass = metaMetadata.GetMetadataClass(MetadataTScope);
                if (metadataClass == null)
                {
                    Debug.WriteLine("No metadata class found for metaMetadata: " + metaMetadata.Name);
                    continue;
                }

                Dictionary <String, MetaMetadata> repositoryByUrlStripped;
                Dictionary <String, List <RepositoryPatternEntry> > repositoryByPattern;

                if (typeof(ClippableDocument).GetTypeInfo().IsAssignableFrom(metadataClass.GetTypeInfo()))
                {
                    repositoryByUrlStripped = _clippableDocumentRepositoryByUrlStripped;
                    repositoryByPattern     = _clippableDocumentRepositoryByPattern;
                }
                else if (typeof(Document).GetTypeInfo().IsAssignableFrom(metadataClass.GetTypeInfo()))
                {
                    repositoryByUrlStripped = _documentRepositoryByUrlStripped;
                    repositoryByPattern     = _documentRepositoryByPattern;
                }
                else
                {
                    continue;
                }

                // We need to check if something is there already
                // if something is there, then we need to check to see if it has its cf pref set
                // if not, then if I am null then I win

                //MetaMetadataSelector selector = metaMetadata.Selectors[0];//Note: Needs to consider all selectors.

                if (metaMetadata.Selectors == null || metaMetadata.Selectors.Count == 0)
                {
                    continue;
                }
                foreach (MetaMetadataSelector selector in metaMetadata.Selectors)
                {
                    ParsedUri strippedPURL = selector.UrlStripped;
                    if (strippedPURL != null)
                    {
                        MetaMetadata inMap = null;
                        repositoryByUrlStripped.TryGetValue(strippedPURL.Stripped, out inMap);
                        if (inMap == null)
                        {
                            repositoryByUrlStripped.Add(strippedPURL.Stripped, metaMetadata);
                        }
                        else
                        {
                            Debug.WriteLine("MetaMetadata already exists in repositoryByUrlStripped for purl\n\t: " +
                                            strippedPURL + " :: " + inMap.Name + " Ignoring MMD: " + metaMetadata.Name);
                        }
                        metaMetadata.MMSelectorType = MMSelectorType.LOCATION;
                    }
                    else
                    {
                        ParsedUri urlPathTree = selector.UrlPathTree;
                        if (urlPathTree != null)
                        {
                            PrefixPhrase <MetaMetadata> pp = urlPrefixCollection.Add(urlPathTree);
                            pp.MappedObject             = metaMetadata;
                            metaMetadata.MMSelectorType = MMSelectorType.LOCATION;
                        }
                        else
                        {
                            // here, url_path_tree is handled through regex.
                            // use .pattern() for comparison
                            String domain = selector.Domain; //??
//                                            (selector.UrlPathTree != null ? selector.UrlPathTree.Domain : null);
                            if (domain != null)
                            {
                                Regex urlPattern = selector.UrlRegex; //??
//                                                   (selector.UrlPathTree == null
//                                                       ? null
//                                                        : new Regex(selector.UrlPathTree.ToString().Replace("*", "[^/]+")));
                                if (urlPattern != null)
                                {
                                    List <RepositoryPatternEntry> bucket;
                                    repositoryByPattern.TryGetValue(domain, out bucket);
                                    if (bucket == null)
                                    {
                                        bucket = new List <RepositoryPatternEntry>(2);
                                        repositoryByPattern.Add(domain, bucket);
                                    }
                                    bucket.Add(new RepositoryPatternEntry(urlPattern, metaMetadata));
                                    metaMetadata.MMSelectorType = MMSelectorType.LOCATION;
                                }
                                else
                                {
                                    // domain only -- no pattern
                                    //TODO: 'PUT' HIDES ERRORS. This is only so that we can identify them
                                    if (_documentRepositoryByDomain.ContainsKey(domain))
                                    {
                                        Debug.WriteLine(
                                            "-----\tError: Adding MMD({0}) for domain({1}), but this domain is already used for MMD({2})",
                                            metaMetadata, domain, _documentRepositoryByDomain[domain]);
                                    }
                                    else
                                    {
                                        _documentRepositoryByDomain.Add(domain, metaMetadata);
                                    }

                                    metaMetadata.MMSelectorType = MMSelectorType.DOMAIN;
                                }
                            }
                        }
                    }
                }
            }
        }