예제 #1
0
        static string UpsertAsset(Google.Apis.Drive.v3.Data.File file, bool update, Stream stream)
        {
            string            externalId = file.Name;
            string            message    = null;
            FileContentSource fcs        = new FileContentSource(stream, externalId, file.MimeType);
            AssetModel        result;
            var emptyDescriptions = new List <AssetDescription>
            {
                new AssetDescription {
                    Description = "", Language = LanguageIdentifier.ById(new Guid("00000000-0000-0000-0000-000000000000"))
                }
            };

            try
            {
                var           fileTask = clientCM.UploadFileAsync(fcs);
                FileReference fr       = fileTask.GetAwaiter().GetResult();

                IEnumerable <AssetDescription> descriptions = new List <AssetDescription>();
                AssetUpsertModel model = new AssetUpsertModel
                {
                    FileReference = fr,
                    Descriptions  = emptyDescriptions
                };
                var createTask = clientCM.CreateAssetAsync(model);
                result = createTask.GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return(message);
        }
예제 #2
0
        public string IdentifyLanguage(Models.Text doc)
        {
            string text = doc.RawText;
            var    li   = LanguageIdentifier.New(AppDomain.CurrentDomain.BaseDirectory + "/classifiers/LangId/langprofiles-word-1_5-nfc-10k.bin.gz", "Vector", -1);
            var    lang = li.Identify(text); // Calling the language identifier -- it

            return(lang);
        }
예제 #3
0
        public MainWindow()
        {
            InitializeComponent();
            languageIdentifier = new LanguageIdentifier();
            LinearGradientBrush gradient = new LinearGradientBrush(Color.FromRgb(185, 255, 246), Color.FromRgb(102, 255, 212), 45);

            MainContainer.Background = gradient;
        }
예제 #4
0
 /// <summary>
 /// Convertit cette cible de génération en string.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     if (LanguageIdentifier == "" && OutputDirectory == "")
     {
         return("");
     }
     return(LanguageIdentifier.ToString() + ":\"" + OutputDirectory.ToString() + "\"");
 }
예제 #5
0
 public string ProfileCheck(string owner, string lang_prof, string text)
 {
     var path = System.IO.Path.Combine(_env.WebRootPath, "Content", "UserData", owner, lang_prof, (lang_prof ?? "").Substring(0, lang_prof.LastIndexOf('_')) + ".bin.gz");
     var lip = LanguageIdentifier.New(path, "Vector", -1);
     var cleaner = Cleaning.MakeCleaner("none");
     List<string> wrds = new List<string>();
     (text ?? "").Split('.', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(t => wrds.AddRange(t.Split(' ', StringSplitOptions.RemoveEmptyEntries)));
     return string.Join(',', wrds.Select(t => lip.Identify(cleaner(t))).Distinct());
 }
예제 #6
0
        private async Task <ContentItemVariantModel <UserModel> > CreateUserVariant(UserModel userModel, ContentItemIdentifier itemIdentifier)
        {
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename("default");
            ContentItemVariantIdentifier variantIdentifier  = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

            ContentItemVariantModel <UserModel> responseVariant = await managementClient.UpsertContentItemVariantAsync <UserModel>(variantIdentifier, userModel);

            return(responseVariant);
        }
예제 #7
0
        public Language Load(ISqlConnectionInfo connection, string value, LanguageIdentifier identifier)
        {
            SqlQueryParameters parameters = new SqlQueryParameters();
            string             parameter  = identifier.ToString();

            parameters.Where = string.Format("[l].{0} = @{0}", parameter);
            parameters.Arguments.Add(parameter, value);
            return(this.Load(connection, parameters));
        }
        private string GetVariantUrlSegment(LanguageIdentifier identifier)
        {
            if (!string.IsNullOrEmpty(identifier.Codename))
            {
                return(string.Format(URL_TEMPLATE_VARIANT_CODENAME, identifier.Codename));
            }

            return(string.Format(URL_TEMPLATE_VARIANT_ID, identifier.Id));
        }
예제 #9
0
        public void BuildContentItemVariantsUrl_ItemCodenameVariantCodename_ReturnsCorrectUrl()
        {
            var itemIdentifier    = ContentItemIdentifier.ByCodename(ITEM_CODENAME);
            var variantIdentifier = LanguageIdentifier.ByCodename(VARIANT_CODENAME);
            var identifier        = new ContentItemVariantIdentifier(itemIdentifier, variantIdentifier);
            var actualUrl         = _builder.BuildVariantsUrl(identifier);
            var expectedUrl       = $"{ENDPOINT}/projects/{PROJECT_ID}/items/codename/{ITEM_CODENAME}/variants/codename/{VARIANT_CODENAME}";

            Assert.Equal(expectedUrl, actualUrl);
        }
예제 #10
0
        public void BuildContentItemVariantsUrl_ItemExternalIdVariantId_ReturnsCorrectUrl()
        {
            var itemIdentifier    = ContentItemIdentifier.ByExternalId(ITEM_EXTERNAL_ID);
            var variantIdentifier = LanguageIdentifier.ById(VARIANT_ID);
            var identifier        = new ContentItemVariantIdentifier(itemIdentifier, variantIdentifier);
            var actualUrl         = _builder.BuildVariantsUrl(identifier);
            var expectedUrl       = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{EXPECTED_ITEM_EXTERNAL_ID}/variants/{VARIANT_ID}";

            Assert.Equal(expectedUrl, actualUrl);
        }
예제 #11
0
        public Language Load(IConnectionInfo connection, string value, LanguageIdentifier identifier)
        {
            ISqlConnectionInfo sqlConnection = connection as ISqlConnectionInfo;

            if (sqlConnection != null)
            {
                return(this.Load(sqlConnection, value, identifier));
            }
            using (sqlConnection = new SqlConnectionInfo(connection, this.Type))
                return(this.Load(sqlConnection, value, identifier));
        }
예제 #12
0
 public List<Models.LangModel> ProfilePost()
 {
     string owner = HttpContext.Request.Form["owner"];
     string lang_prof = HttpContext.Request.Form["lang_prof"];
     var path = System.IO.Path.Combine(_env.WebRootPath, "Content", "UserData", owner, lang_prof, (lang_prof ?? "").Substring(0, lang_prof.LastIndexOf('_')) + ".bin.gz");
     var lip = LanguageIdentifier.New(path, "Vector", -1);
     string text = HttpContext.Request.Form["text"];
     var cleaner = Cleaning.MakeCleaner("none");
     List<string> wrds = new List<string>();
     (text ?? "").Split('.', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(t => wrds.AddRange(t.Split(' ', StringSplitOptions.RemoveEmptyEntries)));
     return wrds.Select(t => lip.Identify(cleaner(t))).GroupBy(t => t).Select(t1 => new Models.LangModel() { lang = t1.Key, count = t1.Count() }).ToList();
 }
예제 #13
0
        internal static async Task <ContentItemVariantModel> PrepareTestVariant(ContentManagementClient client, string languageCodename, object elements, ContentItemModel item)
        {
            var addedItemIdentifier                = ContentItemIdentifier.ByCodename(item.CodeName);
            var addedLanguageIdentifier            = LanguageIdentifier.ByCodename(languageCodename);
            var addedContentItemLanguageIdentifier = new ContentItemVariantIdentifier(addedItemIdentifier, addedLanguageIdentifier);
            var variantUpdateModel = new ContentItemVariantUpsertModel()
            {
                Elements = elements
            };

            return(await client.UpsertContentItemVariantAsync(addedContentItemLanguageIdentifier, variantUpdateModel));
        }
예제 #14
0
        public static (ContentItemIdentifier, LanguageIdentifier, ContentItemVariantIdentifier) GetIdentifiers(string ContentItemCodeName)
        {
            //Retrieive an ItemIdentifier by codename of the content item we want to create a new version of
            ContentItemIdentifier itemIdentifier = ContentItemIdentifier.ByCodename(ContentItemCodeName);

            //Retreive the language identifier of the content item in Konent for the content item (even if we only have one)
            LanguageIdentifier langIdentifier = LanguageIdentifier.ByCodename(RowlingAppConstants.DefaultLanguageCode);

            //Retreive the content item language variant of the content item we want to update (the real unique identifier)
            ContentItemVariantIdentifier identifier = new ContentItemVariantIdentifier(itemIdentifier, langIdentifier);

            return(itemIdentifier, langIdentifier, identifier);
        }
예제 #15
0
        private void PopulateFilterComboBox()
        {
            cmbLanguageFilter.Items.Clear();

            LanguageIdentifier liAll     = new LanguageIdentifier("", m_ResourceManager.GetString("dlgHelpVideos_FilterAll", Thread.CurrentThread.CurrentUICulture));
            LanguageIdentifier liEnglish = new LanguageIdentifier("en", PreferencesManager.LanguageEnglish);
            LanguageIdentifier liFrench  = new LanguageIdentifier("fr", PreferencesManager.LanguageFrench);

            cmbLanguageFilter.Items.Add(liAll);
            cmbLanguageFilter.Items.Add(liEnglish);
            cmbLanguageFilter.Items.Add(liFrench);

            cmbLanguageFilter.SelectedIndex = 0;
        }
예제 #16
0
        private void PopulateFilterComboBox()
        {
            cmbLanguageFilter.Items.Clear();

            LanguageIdentifier liAll     = new LanguageIdentifier("", UpdaterLang.Updater_FilterAll);
            LanguageIdentifier liEnglish = new LanguageIdentifier("en", PreferencesManager.LanguageEnglish);
            LanguageIdentifier liFrench  = new LanguageIdentifier("fr", PreferencesManager.LanguageFrench);

            cmbLanguageFilter.Items.Add(liAll);
            cmbLanguageFilter.Items.Add(liEnglish);
            cmbLanguageFilter.Items.Add(liFrench);

            cmbLanguageFilter.SelectedIndex = 0;
        }
예제 #17
0
        private void SetLanguageIdentifier()
        {
            // CurrentUICulture should correspond to the user's OS language choice.
            CultureInfo currentCulture = CultureInfo.CurrentUICulture;

            if (currentCulture.TwoLetterISOLanguageName.Equals(CultureInfo.GetCultureInfo("de").TwoLetterISOLanguageName) || // only need to check this one?
                currentCulture.TwoLetterISOLanguageName.Equals(CultureInfo.GetCultureInfo("de-de").TwoLetterISOLanguageName))
            {
                languageIdentifier = LanguageIdentifier.German;
            }
            else
            {
                // English for any other UI culture.
                languageIdentifier = LanguageIdentifier.English;
            }
        }
예제 #18
0
        private string DetectLanguage(string Text)
        {
            var languageIdentifier         = new LanguageIdentifier(Server.MapPath("/Wikipedia-Experimental-UTF8Only/"));
            var languageIdentifierSettings = new IvanAkcheurov.NTextCat.Lib.Legacy.LanguageIdentifier.LanguageIdentifierSettings(100);

            var languages           = languageIdentifier.ClassifyText(Text, languageIdentifierSettings).ToList();
            var mostCertainLanguage = languages.FirstOrDefault();

            if (mostCertainLanguage != null)
            {
                return(TryEnrichWithLanguageName(mostCertainLanguage.Item1.Iso639_2T));
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #19
0
        public async Task <string> UpsertTaxonomy(Movie movie, string listing_prediction)
        {
            MovieImport stronglyTypedElements = new MovieImport
            {
                ListedIn = new[] { TaxonomyTermIdentifier.ByCodename(listing_prediction) }
            };

            // Specifies the content item and the language variant
            ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ByCodename(movie.System.Codename);
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename(movie.System.Language);
            ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

            // Upserts a language variant of your content item
            ContentItemVariantModel <MovieImport> response = await client.UpsertContentItemVariantAsync(identifier, stronglyTypedElements);

            return(response.Elements.Title + " updated.");
        }
예제 #20
0
        private async Task <ContentItemVariantModel <ConversationModel> > UpsertConversationVariant(ConversationModel conversation, ContentItemIdentifier itemIdentifier)
        {
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename("default");
            ContentItemVariantIdentifier variantIdentifier  = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

            ContentItemVariantModel <ConversationModel> responseVariant = new ContentItemVariantModel <ConversationModel> {
            };

            try
            {
                responseVariant = await managementClient.UpsertContentItemVariantAsync <ConversationModel>(variantIdentifier, conversation);
            }
            catch (Exception e)
            {
                logger.Debug(e, "Failed to create conversation variant.");
            }
            return(responseVariant);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc()
            .AddJsonOptions(opts =>
            {
                opts.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder =>
            {
                builder.AllowAnyMethod()
                .AllowAnyHeader()
                .AllowAnyOrigin();
            }));

            var li = LanguageIdentifier.New(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Data", "langprofiles-char-1_5-nfc-all.bin.gz"), "Vector", -1);

            services.AddSingleton <LanguageIdentifier>(li);

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder =>
            {
                builder.AllowAnyMethod().AllowAnyHeader()
                .AllowAnyOrigin();
            }));

            services.AddSignalR(hubOptions =>
            {
                hubOptions.EnableDetailedErrors = true;
                hubOptions.KeepAliveInterval    = TimeSpan.FromMinutes(1);
            });
        }
예제 #22
0
        public async static Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext context)
        {
            try
            {
                var config = new ConfigurationBuilder()
                             .SetBasePath(context.FunctionAppDirectory)
                             .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                             .AddEnvironmentVariables()
                             .Build();


                string strLanguageCode = config["KenticoCloudLanguageCode"];

                ContentManagementOptions options = new ContentManagementOptions
                {
                    ProjectId = config["KenticoCloudProjectID"],
                    ApiKey    = config["KenticoCloudContentManagementAPIKey"]
                };

                // Initializes an instance of the ContentManagementClient client
                ContentManagementClient client = new ContentManagementClient(options);

                // Defines the content elements to update
                Task <string> body = new StreamReader(req.Body).ReadToEndAsync();

                ArticleModel NewArticleModel = JsonConvert.DeserializeObject <ArticleModel>(body.Result.ToString());

                // Specifies the content item and the language variant
                ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ByCodename(NewArticleModel.OriginalCodename);
                LanguageIdentifier           languageIdentifier = LanguageIdentifier.ByCodename(strLanguageCode);
                ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

                // Upserts a language variant of your content item
                ContentItemVariantModel <Article> responseUpdate = await client.UpsertContentItemVariantAsync <Article>(identifier, NewArticleModel.NewArticle);

                return((ActionResult) new OkObjectResult($"SUCCESS: Language variant added!"));
            }
            catch (Exception ex)
            {
                return(new OkObjectResult("FAILURE: " + ex.Message));
            }
        }
예제 #23
0
        private void SelectCurrentLanguage()
        {
            bool found = false;

            for (int i = 0; i < cmbLanguage.Items.Count; i++)
            {
                LanguageIdentifier li = (LanguageIdentifier)cmbLanguage.Items[i];

                if (li.Culture.Equals(m_UICultureName))
                {
                    // Matching
                    cmbLanguage.SelectedIndex = i;
                    found = true;
                }
            }
            if (!found)
            {
                // The supported language is not in the combo box. (error).
                cmbLanguage.SelectedIndex = 0;
            }
        }
예제 #24
0
        private void SelectCurrentLanguage()
        {
            bool found = false;

            for (int i = 0; i < cmbLanguage.Items.Count; i++)
            {
                LanguageIdentifier li = (LanguageIdentifier)cmbLanguage.Items[i];

                if (li.Culture.Equals(uiCultureName))
                {
                    // Matching
                    cmbLanguage.SelectedIndex = i;
                    found = true;
                }
            }

            if (!found)
            {
                cmbLanguage.SelectedIndex = 0;
            }
        }
예제 #25
0
        /// <summary>
        /// Adds language variant content to the content item with the supplied codename
        /// </summary>
        /// <param name="codename">Codename of the content item needed</param>
        /// <returns></returns>
        public async Task <Guid> CreateItemVariantAsync(string codename)
        {
            const string htmlMarkup = @"<h1>Some content</h1>
                        <p>This is the content</p>";

            if (!IsValidHtml(htmlMarkup))
            {
                return(Guid.Empty);
            }

            var content = new SimplePage
            {
                PageTitle   = "Test import",
                PageContent = htmlMarkup,
                DishColour  = new[]
                {
                    TaxonomyTermIdentifier.ByCodename("green")
                },
                PageTeaser = new AssetIdentifier[0]
            };

            // Specifies the content item and the language variant
            ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ByCodename(codename);
            LanguageIdentifier           languageIdentifier = LanguageIdentifier.DEFAULT_LANGUAGE;
            ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier: itemIdentifier, languageIdentifier: languageIdentifier);

            // Upserts a language variant of your content item
            try
            {
                ContentItemVariantModel <SimplePage> response = await _managementClient.UpsertContentItemVariantAsync <SimplePage>(identifier, content);

                return(response.Item.Id);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: {ex.Message}");
                return(Guid.Empty);
            }
        }
예제 #26
0
 public Language Load(string value, LanguageIdentifier identifier)
 {
     using (SqlConnectionInfo connection = new SqlConnectionInfo(this.Type))
         return(this.Load(connection, value, identifier));
 }
예제 #27
0
        static void Main(string[] args)
        {
            //Debugger.Launch();
            //MemoryStream s = new MemoryStream();
            //Console.OpenStandardInput().CopyTo(s);
            double defaultWorstAcceptableThreshold  = XmlConvert.ToDouble(ConfigurationManager.AppSettings["WorstAcceptableThreshold"]);
            int    defaultTooManyLanguagesThreshold = XmlConvert.ToInt32(ConfigurationManager.AppSettings["TooManyLanguagesThreshold"]);
            string defaultLanguageModelsDirectory   = ConfigurationManager.AppSettings["LanguageModelsDirectory"];
            int    defaultOccuranceNumberThreshold  = XmlConvert.ToInt32(ConfigurationManager.AppSettings["OccuranceNumberThreshold"]);
            int    defaultMaximumSizeOfDistribution = XmlConvert.ToInt32(ConfigurationManager.AppSettings["MaximumSizeOfDistribution"]);

            bool   opt_help                      = false;
            bool   opt_train                     = false;
            string opt_trainOnFile               = null;
            string opt_classifyFromArgument      = null;
            bool   opt_classifyFromInputPerLine  = false;
            double opt_WorstAcceptableThreshold  = defaultWorstAcceptableThreshold;
            int    opt_TooManyLanguagesThreshold = defaultTooManyLanguagesThreshold;
            string opt_LanguageModelsDirectory   = defaultLanguageModelsDirectory;
            int    opt_OccuranceNumberThreshold  = defaultOccuranceNumberThreshold;
            long   opt_OnlyReadFirstNLines       = long.MaxValue;
            int    opt_MaximumSizeOfDistribution = defaultMaximumSizeOfDistribution;
            bool   opt_verbose                   = false;
            bool   opt_noPrompt                  = false;

            OptionSet option_set = new OptionSet()

                                   .Add("?|help|h", "Prints out the options.", option => opt_help = option != null)

                                   .Add("n|train:", "Trains from the file specified or input stream.",
                                        option =>
            {
                opt_train       = true;
                opt_trainOnFile = option;
            })
                                   .Add("s",
                                        @"Determine language of each line of input.",
                                        option => opt_classifyFromInputPerLine = option != null)
                                   .Add("a=",
                                        @"the program returns the best-scoring language together" + Environment.NewLine +
                                        @"with all languages which are " + defaultWorstAcceptableThreshold + @" times worse (cf option -u). " + Environment.NewLine +
                                        @"If the number of languages to be printed is larger than the value " + Environment.NewLine +
                                        @"of this option (default: " + defaultTooManyLanguagesThreshold + @") then no language is returned, but" + Environment.NewLine +
                                        @"instead a message that the input is of an unknown language is" + Environment.NewLine +
                                        @"printed. Default: " + defaultTooManyLanguagesThreshold + @".",
                                        (int option) => opt_TooManyLanguagesThreshold = option)
                                   .Add("d=",
                                        @"indicates in which directory the language models are" + Environment.NewLine +
                                        @"located (files ending in .lm). Currently only a single" + Environment.NewLine +
                                        @"directory is supported. Default: """ + defaultLanguageModelsDirectory + @""".",
                                        option => opt_LanguageModelsDirectory = option)
                                   .Add("f=",
                                        @"Before sorting is performed the Ngrams which occur this number" + Environment.NewLine +
                                        @"of times or less are removed. This can be used to speed up" + Environment.NewLine +
                                        @"the program for longer inputs. For short inputs you should use" + Environment.NewLine +
                                        @"-f 0." + Environment.NewLine +
                                        @"Default: " + defaultOccuranceNumberThreshold + @".",
                                        (int option) => opt_OccuranceNumberThreshold = option)
                                   .Add("i=",
                                        @"only read first N lines",
                                        (int option) => opt_OnlyReadFirstNLines = option)
                                   .Add("l=",
                                        @"indicates that input is given as an argument on the command line," + Environment.NewLine +
                                        @"e.g. text_cat -l ""this is english text""" + Environment.NewLine +
                                        @"Cannot be used in combination with -n.",
                                        option => opt_classifyFromArgument = option)
                                   .Add("t=",
                                        @"indicates the topmost number of ngrams that should be used." + Environment.NewLine +
                                        @"If used in combination with -n this determines the size of the" + Environment.NewLine +
                                        @"output. If used with categorization this determines" + Environment.NewLine +
                                        @"the number of ngrams that are compared with each of the language" + Environment.NewLine +
                                        @"models (but each of those models is used completely)." + Environment.NewLine +
                                        @"Default: " + defaultMaximumSizeOfDistribution + @".",
                                        (int option) => opt_MaximumSizeOfDistribution = option)
                                   .Add("u=",
                                        @"determines how much worse result must be in order not to be" + Environment.NewLine +
                                        "mentioned as an alternative. Typical value: 1.05 or 1.1. " + Environment.NewLine +
                                        "Default: " + defaultWorstAcceptableThreshold + @".",
                                        (double option) => opt_WorstAcceptableThreshold = option)
                                   .Add("v",
                                        @"verbose. Continuation messages are written to standard error.",
                                        option => opt_verbose = option != null)
                                   .Add(NoPromptSwitch,
                                        @"prevents text input prompt from being shown.",
                                        option => opt_noPrompt = option != null);

            try
            {
                option_set.Parse(args);
            }
            catch (OptionException ex)
            {
                Console.WriteLine("Error occured: " + ex.ToString());
                ShowHelp(option_set);
            }

            if (opt_help)
            {
                ShowHelp(option_set);
                return;
            }

            if (opt_train)
            {
                LanguageModel <ulong> langaugeModel;
                Stream input;
                if (string.IsNullOrEmpty(opt_trainOnFile))
                {
                    if (!opt_noPrompt)
                    {
                        DisplayInputPrompt("Train from text input");
                    }
                    input = Console.OpenStandardInput();
                }
                else
                {
                    input = File.OpenRead(opt_trainOnFile);
                }
                using (input)
                {
                    IEnumerable <UInt64> tokens = new ByteToUInt64NGramExtractor(5, opt_OnlyReadFirstNLines).GetFeatures(input);
                    langaugeModel = new LanguageModel <UInt64>(
                        LanguageModelCreator.CreateLangaugeModel(tokens, opt_OccuranceNumberThreshold, opt_MaximumSizeOfDistribution),
                        new LanguageInfo(null, null, null, null) /*API should ask about language*/);
                }
                using (Stream standardOutput = Console.OpenStandardOutput())
                {
                    new ByteLanguageModelPersister().Save(langaugeModel, standardOutput);
                }
            }
            else
            {
                var languageIdentifier = new LanguageIdentifier(opt_LanguageModelsDirectory, opt_MaximumSizeOfDistribution);
                var settings           = new LanguageIdentifier.LanguageIdentifierSettings(
                    opt_TooManyLanguagesThreshold, opt_OccuranceNumberThreshold, opt_OnlyReadFirstNLines,
                    opt_WorstAcceptableThreshold, 5);
                if (opt_classifyFromArgument != null)
                {
                    var languages = languageIdentifier.ClassifyText(opt_classifyFromArgument, settings);
                    OutputIdentifiedLanguages(languages);
                }
                else if (opt_classifyFromInputPerLine)
                {
                    if (!opt_noPrompt)
                    {
                        DisplayInputPrompt("Classify each line from text input");
                    }
                    using (Stream input = Console.OpenStandardInput())
                    {
                        // suboptimal read performance, but per-line mode is not intended to be used in heavy scenarios
                        foreach (IEnumerable <byte> line in Split <byte>(EnumerateAllBytes(input), true, 0xD, 0xA))
                        {
                            using (var linestream = new MemoryStream(line.ToArray()))
                            {
                                var languages = languageIdentifier.ClassifyBytes(linestream, null, settings);
                                OutputIdentifiedLanguages(languages);
                            }
                        }
                    }
                }
                else
                {
                    if (!opt_noPrompt)
                    {
                        DisplayInputPrompt("Classify text input");
                    }
                    using (Stream input = Console.OpenStandardInput())
                    {
                        var languages = languageIdentifier.ClassifyBytes(input, null, settings);
                        OutputIdentifiedLanguages(languages);
                    }
                }
            }
        }
예제 #28
0
        /// <summary>
        /// </summary>
        /// <param name="elements">The Elements property of the content item to be updated</param>
        /// <param name="codename">If set, the item with the specified code name will be upserted</param>
        static void UpsertSingleItem(Dictionary <string, object> elements, string codename, ContentType type, bool update)
        {
            ContentItemModel contentItem  = null;
            ContentItem      existingItem = null;
            Guid             itemid;

            // Try to get existing content item for updating
            if (update && existingItem == null)
            {
                existingItem = GetExistingContentItem(codename, type.System.Codename);
            }

            // If not updating, create content item first
            if (!update)
            {
                contentItem = CreateNewContentItem(codename, type.System.Codename);
                if (contentItem.Id != null)
                {
                    itemid = contentItem.Id;
                }
                else
                {
                    throw new Exception("Error creating new item.");
                }
            }
            else
            {
                // We are updating existing
                if (existingItem != null)
                {
                    itemid = new Guid(existingItem.System.Id);
                }
                else
                {
                    // Existing item wasn't found, create it
                    contentItem = CreateNewContentItem(codename, type.System.Codename);
                    if (contentItem.Id != null)
                    {
                        itemid = contentItem.Id;
                    }
                    else
                    {
                        throw new Exception("Error creating new item.");
                    }
                }
            }

            // After item is created (or skipped for updateExisting), upsert content
            try
            {
                // Get item variant to upsert
                ContentItemIdentifier        itemIdentifier     = ContentItemIdentifier.ById(itemid);
                LanguageIdentifier           languageIdentifier = LanguageIdentifier.ById(new Guid("00000000-0000-0000-0000-000000000000"));
                ContentItemVariantIdentifier identifier         = new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier);

                elements = ValidateContentTypeFields(elements, type);

                // Set target element value
                ContentItemVariantUpsertModel model = new ContentItemVariantUpsertModel()
                {
                    Elements = elements
                };

                // Upsert item
                var upsertTask = clientCM.UpsertContentItemVariantAsync(identifier, model);
                var response   = upsertTask.GetAwaiter().GetResult();
            }
            catch (ContentManagementException e)
            {
                if (e.Message.ToLower().Contains("cannot update published"))
                {
                    throw new Exception("This tool cannot currently update published content. If you wish to update a published item, you will first need to unpublish it within Kentico Kontent.");
                }
            }
        }
 /// <summary>
 /// Creates instance of content item variant identifier.
 /// </summary>
 /// <param name="itemIdentifier">The identifier of the content item.</param>
 /// <param name="languageIdentifier">The identifier of the language.</param>
 public ContentItemVariantIdentifier(ContentItemIdentifier itemIdentifier, LanguageIdentifier languageIdentifier)
 {
     ItemIdentifier     = itemIdentifier;
     LanguageIdentifier = languageIdentifier;
 }
예제 #30
0
 public LanguageController(LanguageIdentifier li, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, Microsoft.AspNetCore.SignalR.IHubContext<Hubs.ProgressHub> hub)
 {
     _li = li;
     _env = env;
     _hub = hub;
 }