public async Task <ActionResult> Create([Bind(Include = "Id,LinkString,StatementId")] Reference referenceModel)
        {
            if (ModelState.IsValid)
            {
                var urlClassifier = new URLClassification();

                referenceModel.Id        = Guid.NewGuid();
                referenceModel.CreatedBy = User.Identity.Name;
                referenceModel.Tags      = new List <string>();
                referenceModel.Bias      = await urlClassifier.ClassifyOutletDescription(referenceModel.Link.Host);

                // Add Reference
                db.References.Add(referenceModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Statement", new { id = referenceModel.StatementId }));
            }

            return(View(referenceModel));
        }
Exemple #2
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Text")] TextBlobModel textBlobModel)
        {
            if (ModelState.IsValid)
            {
                var statementProducer = new StatementProducer(new LuisClientFactory("https://eastus2.api.cognitive.microsoft.com/luis/v2.0/apps/79af6370-41bd-4d03-9c7c-5f234eb6049c?subscription-key=784cc32302a84581ab894febc8775393&timezoneOffset=0&verbose=true&q=").Create());
                var finder            = FinderFactory.CreateFinder();
                var urlClassifier     = new URLClassification();

                textBlobModel.Id        = Guid.NewGuid();
                textBlobModel.CreatedBy = User.Identity.Name;

                var statementTasks = Task.WhenAll(statementProducer.GetStatements(textBlobModel));
                var statements     = await statementTasks;

                // Generate references for each statement
                var statementTasks2 = statements
                                      .Select(async statement =>
                {
                    if (statement.Classification == StatementClassification.Other)
                    {
                        return(statement);
                    }

                    var referenceTasks = (await finder.FindSuggestions(statement.Text)).Select(async uri =>
                    {
                        var bias = (await urlClassifier.ClassifyOutletDescription(uri.Host));

                        return(new Reference
                        {
                            Id = Guid.NewGuid(),
                            CreatedBy = "System",
                            Link = uri,
                            Tags = new List <string>(),
                            Bias = bias == null ? null : new Bias(bias, Guid.NewGuid())
                        });
                    });

                    var references = await Task.WhenAll(referenceTasks);
                    return(new Statement(statement, references.ToList()));
                });

                var statementsWithReferences = await Task.WhenAll(statementTasks2);

                textBlobModel.Statements = statementsWithReferences.ToList();

                var entityFinder = new EntityFinder();
                var entities     = await entityFinder.GetEntities(textBlobModel.Text);

                textBlobModel.Entities = entities
                                         .Select(e => new Entity
                {
                    Id        = Guid.NewGuid(),
                    CreatedBy = "Microsoft Entity Linking",
                    Name      = entityFinder.ExtractEntityName(e),
                    WikiUrl   = entityFinder.ExtractEntityWikiUrlString(e),
                    Matches   = entityFinder.ExtractMatches(e)
                                .Select(tuple => new Match
                    {
                        Id     = Guid.NewGuid(),
                        Text   = tuple.Item1,
                        Offset = tuple.Item2
                    })
                                .ToList()
                })
                                         .ToList();

                // Save TextBlob
                db.TextBlobModels.Add(textBlobModel);
                await db.SaveChangesAsync();
                await FetchPersonas(textBlobModel);

                return(View(textBlobModel));
            }

            return(View(textBlobModel));
        }
        // GET: Sentences/Details
        public async Task <IActionResult> Details(Guid Id)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }
            var _sent = _context.Sentences
                        .SingleOrDefault(s => (s.Id == Id && s.Type == SentenceType.OBJECTIVE));

            if (_sent == null)
            {
                return(NotFound());
            }
            var factory = new FinderFactory(_configuration["Authentication:Finder:Key"]);
            var finder  = factory.CreateFinder();

            var urlClassifier  = new URLClassification();
            var referenceTasks = (await finder.FindSuggestions(_sent.Content))
                                 .Select(async uri =>
            {
                var bias = await urlClassifier.ClassifyOutletDescription(uri.Host);
                return(new Reference
                {
                    Id = Guid.NewGuid(),
                    CreatedBy = "System",
                    Link = uri,
                    Tags = new List <string>(),
                    Bias = bias == null ? null : new Bias(bias, Guid.NewGuid())
                });
            });
            var references = await Task.WhenAll(referenceTasks);

            var entityFinder = new EntityFinder(_configuration["Authentication:Entity:Key"]);

            var entityList = (await entityFinder.GetEntities(_sent.Content))
                             .Select(e => new Entity
            {
                Id        = Guid.NewGuid(),
                CreatedBy = "Microsoft Entity Linking",
                Name      = entityFinder.ExtractEntityName(e),
                WikiUrl   = entityFinder.ExtractEntityWikiUrlString(e),
                Matches   = entityFinder.ExtractMatches(e)
                            .Select(tuple => new Match
                {
                    Id     = Guid.NewGuid(),
                    Text   = tuple.Item1,
                    Offset = tuple.Item2
                })
                            .ToList()
            }).ToList();
            var entityTasks = entityList
                              .Select(async e =>
            {
                e.Persona = PersonasDBLookups.ByName[e.Name].FirstOrDefault();
                if (e.Persona != null)
                {
                    await e.Persona.FetchRecentStatements();
                }
                return(e);
            });
            var entities = await Task.WhenAll(entityTasks);

            return(Json(new
            {
                References = references,
                Entities = entities
            }));
        }