Пример #1
0
        static void Main(string[] args)
        {
            CommandLineOption opt    = GetDefaultOption();
            Parser            parser = new Parser();
            var stopwatch            = new Stopwatch();

            try
            {
                parser.ParseArguments(args, opt);

                string[] info = File.ReadAllLines(opt.info);

                int sourceAuthorNum       = Convert.ToInt32(info[0]);
                int targetAuthorNum       = Convert.ToInt32(info[1]);
                int sourcePaperNum        = Convert.ToInt32(info[2]);
                int targetPaperNum        = Convert.ToInt32(info[3]);
                int collaborationPaperNum = Convert.ToInt32(info[4]);

                List <string> papers  = File.ReadAllLines(opt.papers).ToList();
                List <string> authors = File.ReadAllLines(opt.authors).ToList();

                var sourcePapers        = papers.Take(sourcePaperNum).ToArray();
                var targetPapers        = papers.Skip(sourcePaperNum).Take(targetPaperNum).ToArray();
                var collaborationPapers = papers.Skip(sourcePaperNum + targetPaperNum).ToArray();

                var sourceAuthors        = authors.Take(sourcePaperNum).ToArray();
                var targetAuthors        = authors.Skip(sourcePaperNum).Take(targetPaperNum).ToArray();
                var collaborationAuthors = authors.Skip(sourcePaperNum + targetPaperNum).ToArray();

                int vocabSize = 12;

                Corpora sourceCor = new Corpora(vocabSize, sourceAuthorNum);
                sourceCor.LoadDataFile(sourcePapers, sourceAuthors);
                ACTPhraseSampling sourceModel = new ACTPhraseSampling();
                sourceModel.TrainNewModel(sourceCor, opt, "outSource.txt");

                Corpora targetCor = new Corpora(vocabSize, targetAuthorNum);
                targetCor.LoadDataFile(targetPapers, targetAuthors);
                ACTPhraseSampling targetModel = new ACTPhraseSampling();
                targetModel.TrainNewModel(targetCor, opt, "outTarget.txt");

                Corpora collaborationCor = new Corpora(vocabSize, 0);
                collaborationCor.LoadDataFile(collaborationPapers, collaborationAuthors);
                CTLPhraseSampling collaborationModel = new CTLPhraseSampling(sourceModel, targetModel);
                collaborationModel.TrainNewModel(collaborationCor, opt, "outColl.txt");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Пример #2
0
        public CTLPhraseSampling(ACTPhraseSampling sourceModel, ACTPhraseSampling targetModel)
        {
            M   = 0;
            Voc = 0;
            K   = sourceModel.K + targetModel.K;
            //alpha = 0.1;
            //beta = 0.1;
            gamma  = 3.0;
            gammaT = 0.1;

            rnd = new Random();

            this.sourceModel = sourceModel;
            this.targetModel = targetModel;
        }