Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new object implementing the IMatcher interface for
        /// finding the specified patterns.
        /// </summary>
        /// <param name="patterns">The patterns to search for in text.</param>
        /// <param name="algorithm">
        /// The algorithm used for underlying implementation.
        /// </param>
        public virtual IMatcher Create(List <string> patterns, MatchAlgorithm algorithm = MatchAlgorithm.Default)
        {
            if (patterns.Count == 0)
            {
                throw new ArgumentException("No patterns were given.");
            }

            switch (algorithm)
            {
            case MatchAlgorithm.Default:
                if (patterns.Count < 3)
                {
                    return(new RegexMatcher(patterns));
                }

                return(new AhoMatcher(patterns));

            case MatchAlgorithm.AhoCorasick:
                return(new AhoMatcher(patterns));

            case MatchAlgorithm.Regex:
                return(new RegexMatcher(patterns));

            default:
                throw new ArgumentException("Invalid algorithm given");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new object implementing the IMatcher interface for
        /// finding the specified patterns.
        /// </summary>
        /// <param name="patterns">The patterns to search for in text.</param>
        /// <param name="algorithm">
        /// The algorithm used for underlying implementation.
        /// </param>
        public virtual IMatcher Create(List<string> patterns, MatchAlgorithm algorithm = MatchAlgorithm.Default)
        {
            if (patterns.Count == 0)
                throw new ArgumentException("No patterns were given.");

            switch (algorithm)
            {
                case MatchAlgorithm.Default:
                    if (patterns.Count < 3)
                        return new RegexMatcher(patterns);

                    return new AhoMatcher(patterns);

                case MatchAlgorithm.AhoCorasick:
                    return new AhoMatcher(patterns);

                case MatchAlgorithm.Regex:
                    return new RegexMatcher(patterns);

                default:
                    throw new ArgumentException("Invalid algorithm given");
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index()
        {
            // Validate, else redirect to /login
            var cookies = Request.Cookies["token"];

            if (cookies == null)
            {
                return(Redirect("/login"));
            }
            InfoHelper.IsLoggedIn = true;

            // Get current active user
            string    email       = SecurityHelper.GetLoggedInUser(cookies);
            UserModel currentUser = await Dataprovider.Instance.ReadUserByEmail(email);

            currentUser.Images = await Dataprovider.Instance.GetUserImagesByUserID(currentUser.ID);

            currentUser.Interests = await Dataprovider.Instance.GetUserInterests(currentUser.ID);

            // Get all active users (todo; limit this somehow, will be ass-slow if database gets larger)
            List <UserModel> users = new List <UserModel>();

            if (currentUser.Gender == "Man")
            {
                users = await Dataprovider.Instance.ReadAllFemale();
            }
            else
            {
                users = await Dataprovider.Instance.ReadAllMale();
            }


            foreach (var user in users)
            {
                user.Images = await Dataprovider.Instance.GetUserImagesByUserID(user.ID);

                user.Interests = await Dataprovider.Instance.GetUserInterests(user.ID);
            }

            var relationships = await Dataprovider.Instance.ReadUserByRelationships(currentUser.ID);

            foreach (var relationship in relationships)
            {
                if (relationship.UserID1 == currentUser.ID)
                {
                    users.RemoveAll(User => User.ID == relationship.UserID2);
                }
                else
                {
                    users.RemoveAll(User => User.ID == relationship.UserID1);
                }
            }

            // Make match thingy
            // Convert usermodels => MatchUserDtocs model
            List <MatchUserDtocs> usersToBeMatched = new List <MatchUserDtocs>();

            usersToBeMatched = Converters.ConvertUserModelToMatchUserDto(users);
            // Match percentage gets added to MatchUserDtocs.ProtagonistMatchPercentage property
            MatchAlgorithm.CalculateMatchPercentage(currentUser, ref usersToBeMatched);

            // Sort by best matches first..?
            usersToBeMatched = usersToBeMatched.OrderBy(x => x.ProtagonistMatchPercentage).ToList();

            // ... Order sorted the wrong way apparently
            usersToBeMatched.Reverse();

            //(List<MatchUserDtocs>, UserModel) homeTupleThingyTooTiredToNameVariablesProperly = (usersToBeMatched, currentUser);

            return(View(usersToBeMatched));
        }