Ejemplo n.º 1
0
        /// <summary>
        /// query all google custom searches for a document statistic
        /// </summary>
        /// <param name="documentStatistics"></param>
        public void Check(DocumentStatistics documentStatistics)
        {
            foreach (string sentence in documentStatistics.getSentences())
            {
                LinkedList <GoogleSearchResult> googleSearchResults = new LinkedList <GoogleSearchResult>();

                foreach (GoogleCustomSearch customSearch in customSearchs)
                {
                    Uri             apiUri          = new Uri(API + "?key=" + apikey + "&cx=" + customSearch.id + "&q=" + sentence);
                    HTTPRestRequest httpRestRequest = new HTTPRestRequest(apiUri.ToString());
                    dynamic         json            = httpRestRequest.MakeRequest();

                    //no results
                    if (json != null && json.items != null)
                    {
                        int count = 0;
                        foreach (dynamic item in json.items)
                        {
                            //A bit ugly but we need it because its the easiest way too break
                            // out of the loop.
                            if (count >= 3)
                            {
                                break;
                            }

                            googleSearchResults.AddLast(new GoogleSearchResult(customSearch.name, (string)item.title, (string)item.link, (string)item.snippet));
                            count++;
                        }
                    }
                }

                documentStatistics.updateGoogleSearchResults(sentence, googleSearchResults);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// query pmc and store results in the document statistic
        /// </summary>
        /// <param name="documentStatistics"></param>
        public void Check(DocumentStatistics documentStatistics)
        {
            foreach (string sentence in documentStatistics.getSentences())
            {
                LinkedList <EuropaPMCSearchResult> europaPMCSearchResult = new LinkedList <EuropaPMCSearchResult>();

                Uri apiUri = new Uri(API + "query=" + sentence + "&resultType=core&synonym=NO&cursorMark=*&pageSize=3&format=json");

                HTTPRestRequest httpRestRequest = new HTTPRestRequest(apiUri.ToString());
                dynamic         json            = httpRestRequest.MakeRequest();

                if (json != null)
                {
                    foreach (dynamic item in json.resultList.result)
                    {
                        if (item.abstractText != null)
                        {
                            europaPMCSearchResult.AddLast(new EuropaPMCSearchResult((string)item.title, (string)item.authorString, (string)item.abstractText, (string)item.pubYear, (string)item.fullTextUrlList.fullTextUrl[0].url));
                        }
                    }
                }

                documentStatistics.updateEuropaPMCSearchResults(sentence, europaPMCSearchResult);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Analyzes all the given sentences and queries them against the different apis
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="URLsources"></param>
        /// <param name="Sources"></param>
        /// <returns></returns>
        public List <Plagiat <string> > Check(List <string> origin, List <Uri> URLsources, List <String> Sources)
        {
            //google search with custom search
            GoogleSearch googleSearch = new GoogleSearch(new Uri("https://www.googleapis.com/customsearch/v1"));

            //europa pmc search for academic literatur in life science
            EuropaPMCSearch europaPMCSearch = new EuropaPMCSearch(new Uri("https://www.ebi.ac.uk/europepmc/webservices/rest/search?"));

            //create document statistics
            DocumentStatistics documentStatistics = new DocumentStatistics(origin);

            googleSearch.Check(documentStatistics);
            europaPMCSearch.Check(documentStatistics);

            //starting azure congitive services to interpret sentence
            // Create a client
            ITextAnalyticsAPI client = new TextAnalyticsAPI();

            client.AzureRegion     = AzureRegions.Westeurope;
            client.SubscriptionKey = "<placekey>";

            // Extracting language
            LanguageBatchResult languagesDetected = client.DetectLanguage(
                new BatchInput(documentStatistics.getBatchInput())
                );

            //store results
            foreach (var document in languagesDetected.Documents)
            {
                documentStatistics.updateSentenceLanguage(document.Id, document.DetectedLanguages[0].Iso6391Name);
            }

            // Getting key-phrases
            KeyPhraseBatchResult keyPhares = client.KeyPhrases(
                new MultiLanguageBatchInput(documentStatistics.getMultiLanguageBatchInput())
                );

            // Printing keyphrases
            foreach (var document in keyPhares.Documents)
            {
                documentStatistics.updateKeyPhares(document.Id, (List <string>)document.KeyPhrases);
            }

            return(documentStatistics.getPossiblePlagiates());
        }