当前位置: 首页>>代码示例>>C#>>正文


C# ITokenizer.Tokenize方法代码示例

本文整理汇总了C#中ITokenizer.Tokenize方法的典型用法代码示例。如果您正苦于以下问题:C# ITokenizer.Tokenize方法的具体用法?C# ITokenizer.Tokenize怎么用?C# ITokenizer.Tokenize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITokenizer的用法示例。


在下文中一共展示了ITokenizer.Tokenize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AuthModule

        public AuthModule(ITokenizer tokenizer, Users users)
            : base("/auth")
        {
            Post["/"] = x =>
            {
                var request = this.Bind<AuthRequest>();

                if (string.IsNullOrEmpty(request.Identifier))
                {
                    return HttpStatusCode.Unauthorized;
                }
                var user = users.ValidateUsernameOrEmail(request.Identifier, request.Password);
                
                if (user == null)
                {
                    return HttpStatusCode.Unauthorized;
                }

                var userIdentity = new UserIdentity(user);
                var token = tokenizer.Tokenize(userIdentity, Context);

                return new
                {
                    Token = token,
                    Username = user.Username,
                    UserId = user.Id
                };
            };

            Get["/"] = _ =>
            {
                this.RequiresAuthentication();
                return Context.CurrentUser;
            };
        }
开发者ID:ryascl,项目名称:design-challenge-server-clr,代码行数:35,代码来源:AuthModule.cs

示例2: GetWordFrequency

		/// <summary>
		/// Gets a Hashtable of words and integers representing the number of each word.
		/// </summary>
		/// <param name="input">The string to get the word frequency of.</param>
		/// <param name="caseSensitive">True if words should be treated as separate if they have different casing.</param>
		/// <param name="tokenizer">A instance of ITokenizer.</param>
		/// <param name="stopWordProvider">An instance of IStopWordProvider.</param>
		/// <returns></returns>
		public static Hashtable GetWordFrequency(string input, bool caseSensitive, ITokenizer tokenizer, IStopWordProvider stopWordProvider)
		{
			string convertedInput = input;
			if (!caseSensitive)
				convertedInput = input.ToLower();

			string[] words = tokenizer.Tokenize(convertedInput);
			Array.Sort(words);

			string[] uniqueWords = GetUniqueWords(words);

			Hashtable result = new Hashtable();
			for (int i = 0; i < uniqueWords.Length; i++)
			{
				if (stopWordProvider == null || (IsWord(uniqueWords[i]) && !stopWordProvider.IsStopWord(uniqueWords[i])))
				{
					if (result.ContainsKey(uniqueWords[i]))
						result[uniqueWords[i]] = (int)result[uniqueWords[i]] + CountWords(uniqueWords[i], words);
					else
						result.Add(uniqueWords[i], CountWords(uniqueWords[i], words));
				}
			}

			return result;
		}
开发者ID:bonchovylkov,项目名称:Sport-Classifier,代码行数:33,代码来源:Utilities.cs

示例3: AuthModule

        public AuthModule(ITokenizer tokenizer)
            : base("/auth")
        {
            Post["/"] = x =>
                {
                    var userName = (string)this.Request.Form.UserName;
                    var password = (string)this.Request.Form.Password;

                    var userIdentity = UserDatabase.ValidateUser(userName, password);

                    if (userIdentity == null)
                    {
                        return HttpStatusCode.Unauthorized;
                    }

                    var token = tokenizer.Tokenize(userIdentity, Context);

                    return new
                        {
                            Token = token,
                        };
                };

            Get["/validation"] = _ =>
                {
                    this.RequiresAuthentication();
                    return "Yay! You are authenticated!";
                };

            Get["/admin"] = _ =>
            {
                this.RequiresClaims(new[] { "admin" });
                return "Yay! You are authorized!";
            };
        }
开发者ID:jbattermann,项目名称:Nancy,代码行数:35,代码来源:AuthModule.cs

示例4: AuthModule

    public AuthModule(ITokenizer tokenizer)
        : base("/auth")
    {
        Options["/"] = o =>
        {
            return HttpStatusCode.OK;
        };

        Post["/"] = x =>
        {
            var userName = (string)this.Request.Form.UserName;

            var password = (string)this.Request.Form.Password;

            var userIdentity = UserDatabase.ValidateUser(userName, password);

            if(userIdentity == null)
            {
                return HttpStatusCode.Unauthorized;
            }

            var token = tokenizer.Tokenize(userIdentity, Context);
            return new
            {
                Token = token
            };
        };
    }
开发者ID:duhaly,项目名称:NancyFxConsole,代码行数:28,代码来源:AuthModule.cs

示例5: AuthModule

        public AuthModule(ILogger<AuthModule> logger,
            IUserManager userManager,
            ITokenizer tokenizer)
            : base("auth")
        {
            Get["/setup"] = _ => !userManager.HasUsers();

            Post["/login"] = _ =>
            {
                var userData = this.Bind<UserDto>();

                // First login creates user
                if (!userManager.HasUsers())
                {
                    logger.Info("Creating user account {UserName}.", userData.UserName);
                    userManager.CreateUser(userData.UserName, userData.Password);
                }

                var user = userManager.GetUser(userData.UserName, userData.Password);

                if (user == null)
                {
                    logger.Warn("Invalid username/password: {UserName}.", userData.UserName);
                    return HttpStatusCode.Unauthorized;
                }

                var identity = new UserIdentity(user.UserName, user.Claims);
                var token = tokenizer.Tokenize(identity, Context);

                return new
                {
                    Token = token
                };
            };
        }
开发者ID:DNIDNL,项目名称:hadouken,代码行数:35,代码来源:AuthModule.cs

示例6: AuthModule

        public AuthModule(ITokenizer tokenizer)
            : base("/auth")
        {
            Post["/"] = x =>
            {
                var userName = this.Request.Form.UserName;
                var password = this.Request.Form.Password;

                var userIdentity = new UserIdentity();

                var token = tokenizer.Tokenize(userIdentity, Context);

                return new
                {
                    Token = token
                };
            };

            Get["/validation"] = _ =>
            {
                this.RequiresAuthentication();
                return "Yay! You are authenticated!";
            };

            Get["/admin"] = _ =>
            {
                this.RequiresClaims(new[] { "admin" });
                return "Yay! You are authorized!";
            };
        }
开发者ID:joeyulivecn,项目名称:NancyDemo,代码行数:30,代码来源:AuthModule.cs

示例7: AuthModule

        public AuthModule(IConfiguration configuration, IAuthenticationManager authenticationManager, ITokenizer tokenizer)
            : base("auth")
        {
            Get["/setup"] = _ => string.IsNullOrEmpty(configuration.UserName);

            Post["/login"] = _ =>
            {
                var loginParameters = this.Bind<LoginParameters>();

                if (string.IsNullOrEmpty(configuration.UserName))
                {
                    SetAuth(configuration, loginParameters);
                }

                if (!authenticationManager.IsValid(loginParameters.UserName, loginParameters.Password))
                {
                    return HttpStatusCode.Unauthorized;
                }

                var identity = new UserIdentity(loginParameters.UserName, null);
                var token = tokenizer.Tokenize(identity, Context);

                return new
                {
                    Token = token
                };
            };
        }
开发者ID:KyulingLee,项目名称:hadouken,代码行数:28,代码来源:AuthModule.cs

示例8: AuthModule

        public AuthModule(ITokenizer tokenizer)
            : base("/auth")
        {
            this.EnableCors();

            Post["/"] = x =>
            {
                var userName = (string) this.Request.Form.UserName;
                var password = (string) this.Request.Form.Password;

                var userIdentity = UserDatabase.ValidateUser(userName, password);

                if (userIdentity == null)
                {
                    return HttpStatusCode.Unauthorized;
                }

                var token = tokenizer.Tokenize(userIdentity, Context);

                return new
                {
                    access_token = token,
                };
            };

            Get["/validation"] = _ =>
            {
                this.RequiresAuthentication();

                return HttpStatusCode.OK;
            };

            Options["/authenticated-content"] = _ => HttpStatusCode.OK;

            Get["/authenticated-content"] = _ =>
            {
                this.RequiresAuthentication();

                return Response.AsJson(new
                {
                    message = "Yay! You are authenticated! :)"
                });
            };

            Get["/admin"] = _ =>
            {
                this.RequiresClaims(new[] { "admin" });

                return Response.AsJson(new
                {
                    message = "Yay! You are the admin :P"
                });
            };

            Options["/"] = _ => HttpStatusCode.OK;
        }
开发者ID:duhaly,项目名称:token-authentication-sample,代码行数:56,代码来源:AuthModule.cs

示例9: TestWithAMillionWords

 public static void TestWithAMillionWords(ITokenizer tokenizer)
 {
     string text = File.ReadAllText(path, Encoding.UTF8);
     Stopwatch sw = Stopwatch.StartNew();
     for (int i = 0; i < 1000; i++)
     {
         tokenizer.Tokenize(text);
     }
     sw.Stop();
     Console.WriteLine("Time taken to tokenizer 85 MB text: {0}ms", sw.Elapsed.TotalMilliseconds);
     GC.Collect();
 }
开发者ID:hrzafer,项目名称:nuve,代码行数:12,代码来源:TokenizerBenchmark.cs

示例10: TestTokenizer

        internal static void TestTokenizer(ITokenizer tokenizer) {
            var tokens = tokenizer.Tokenize("Sounds like it's not properly thought through!");

            Assert.AreEqual(9, tokens.Length);
            Assert.AreEqual("Sounds", tokens[0]);
            Assert.AreEqual("like", tokens[1]);
            Assert.AreEqual("it", tokens[2]);
            Assert.AreEqual("'s", tokens[3]);
            Assert.AreEqual("not", tokens[4]);
            Assert.AreEqual("properly", tokens[5]);
            Assert.AreEqual("thought", tokens[6]);
            Assert.AreEqual("through", tokens[7]);
            Assert.AreEqual("!", tokens[8]);
        }
开发者ID:lovethisgame,项目名称:SharpNL,代码行数:14,代码来源:TokenizerMETest.cs

示例11: AuthModule

        public AuthModule(ITokenizer tokenizer)
            : base("/auth")
        {
            Post["/token"] = x =>
            {
                IUserIdentity indentity = new BasicIdentity { UserName = "admin", Claims = new List<string> { "Money", "Power" } };
                var token = tokenizer.Tokenize(indentity, Context);
                return new { Token = token };
            };

            Post["/apikey"] = x =>
            {
                return new { ApiKey = "c5c16da7-e0fc-4e14-a522-3dab15a7a593" };
            };
        }
开发者ID:divyang4481,项目名称:DataManagerDev,代码行数:15,代码来源:AuthModule.cs

示例12: ImportSparse

        public static IDictionary<string, double>[] ImportSparse(string filePath, IReworder reworder, IReader reader, ITokenizer tokenizer)
        {
            List<IDictionary<string, double>> encyclopedia = new List<IDictionary<string, double>>();
            int linesRead = 0;

            foreach (string line in LinesEnumerator.YieldLines(filePath))
            {
                IDictionary<string, double> res = tokenizer.Tokenize(reader.Read(ReworderHelper.Map(line,reworder)));

                encyclopedia.Add(res);
                linesRead++;

                if ((linesRead % DisplaySettings.PrintProgressEveryLine) == 0)
                {
                    Console.Write('.');
                }
            }
            return encyclopedia.ToArray();
        }
开发者ID:turboNinja2,项目名称:Rob-The-Robot,代码行数:19,代码来源:EncyclopediaReader.cs

示例13: AuthenticateModule

        public AuthenticateModule(ITokenizer tokenizer)
        {
            Post["/authenticate"] = x => {
            var user = this.Bind<User>();

            var username = Environment.GetEnvironmentVariable(adminKey);
            var password = Environment.GetEnvironmentVariable(passwordKey);

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) return HttpStatusCode.Unauthorized;
            if (user.Username != username || user.Password != password) return HttpStatusCode.Unauthorized;

            var identity = new UserIdentity {
              UserName = user.Username,
              Claims = new[] { "admin" }
            };
            var token = tokenizer.Tokenize(identity, Context);
            return Response.AsJson(new Authenticate { Token = token });
              };
        }
开发者ID:schlos,项目名称:denver-schedules-api,代码行数:19,代码来源:AuthenticateModule.cs

示例14: SecureModule

        public SecureModule(ITokenizer tokenizer)
            : base("/secure")
        {
            this.RequiresAuthentication();

            Get["/"] = _ =>
            {
                ViewBag.CurrentUser = this.Context.CurrentUser.UserName;
                return View["secure"];
            };

            Get["/token"] = _ =>
            {
                ViewBag.Token = tokenizer.Tokenize(Context.CurrentUser, Context);
                return View["token"];
            };

            Get["/logout"] = _ =>
            {
                return this.LogoutAndRedirect("/");
            };
        }
开发者ID:ken200,项目名称:Tokenken2,代码行数:22,代码来源:MyModule.cs

示例15: AuthModule

        public AuthModule(IMongoDatabase database, ITokenizer tokenizer)
            : base("/api/auth")
        {
            Post["/"] = x =>
            {
                User user = this.Bind<User>(); // Nancy.ModelBinding

                var userIdentity = UserDAO.ValidateUser(user);

                if (userIdentity == null)
                {
                    return HttpStatusCode.Unauthorized;
                }

                var token = tokenizer.Tokenize(userIdentity, Context);

                return new
                {
                    id = token,
                    user = new {
                        id = userIdentity.UserName,
                        role = userIdentity.Claims
                    }
                };
            };

            Get["/validation"] = _ =>
            {
                this.RequiresAuthentication();
                return "Yay! You are authenticated!";
            };

            Get["/admin"] = _ =>
            {
                this.RequiresClaims(new[] { "admin" });
                return "Yay! You are authorized!";
            };
        }
开发者ID:RafaelDelboni,项目名称:Angular-WebAPI-MongoDB-TokenAuth,代码行数:38,代码来源:AuthModule.cs


注:本文中的ITokenizer.Tokenize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。