//Crea un documento Lucene a partir de los Datos del documento Xively
        private static Document createLuceneDocumentXyvely(UrlDocument URLDocument)
        {
            Document document = new Document();

            //Identificadores. Se almacenan pero no se indexan ni analizan
            document.Add(new Field("Id", URLDocument.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            document.Add(new Field("feed", URLDocument.URL, Field.Store.YES, Field.Index.NOT_ANALYZED));
            //Campos de texto a ser analizados e indexados
            document.Add(new Field("Descripcion", URLDocument.Resume, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
            document.Add(new Field("Title", URLDocument.Tittle, Field.Store.YES, Field.Index.ANALYZED));
            document.Add(new Field("Tags", URLDocument.Tags, Field.Store.YES, Field.Index.ANALYZED));
            document.Add(new Field("Conceptos", URLDocument.ConceptosLista(), Field.Store.YES, Field.Index.ANALYZED));
            document.Add(new Field("DataStreams", URLDocument.Datastreams_feed, Field.Store.YES, Field.Index.ANALYZED));
            //Campos que se almacenan pero no se analizan pero si se indexan
            document.Add(new Field("Location", URLDocument.Localizacion_name, Field.Store.YES, Field.Index.NOT_ANALYZED));
            document.Add(new Field("Domain", URLDocument.Domain, Field.Store.YES, Field.Index.NOT_ANALYZED));
            //Campos almacenados por propósitos de información temparana del feed, por ello no se analizan y no se indexan
            document.Add(new Field("Website", URLDocument.Website, Field.Store.YES, Field.Index.NO));
            document.Add(new Field("Elevacion", URLDocument.Elevacion, Field.Store.YES, Field.Index.NO));
            document.Add(new Field("Latitud", URLDocument.Latitud, Field.Store.YES, Field.Index.NO));
            document.Add(new Field("Longitud", URLDocument.Longitud, Field.Store.YES, Field.Index.NO));

            //document.Add(new Field(FIELD_CONTENT_NAME, URLDocument.Resume, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
            return(document);
        }
Esempio n. 2
0
        /// <summary>
        /// Submitting URL to plagiarism scan
        /// </summary>
        /// <param name="scanId">A unique scan Id</param>
        /// <param name="documentModel">The url and scan properties</param>
        /// <returns>A task that represents the asynchronous submit operation.</returns>
        public async Task SubmitUrlAsync(string scanId, UrlDocument documentModel, string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentException("Token is mandatory", nameof(token));
            }

            if (documentModel.Url == null)
            {
                throw new ArgumentException("Url is mandatory.", nameof(documentModel.Url));
            }

            string requestUri = $"{this.CopyleaksApiServer}{this.ApiVersion}/scans/submit/url/{scanId}";

            await SubmitAsync(documentModel, requestUri, token).ConfigureAwait(false);
        }
        public static List <UrlDocument> BuscarEnIndiceSemantico(String original, Boolean usarEspañol)
        {
            //Lista de documentos resultado de la búsqueda
            List <Document>    DocumenResult = new List <Document>();
            List <UrlDocument> UrlResult     = new List <UrlDocument>();

            //Llama al procedimiento que realiza la busqueda
            if (usarEspañol)
            {
                DocumenResult = moreLikeThisAnalyzer(original, StopFilter.MakeStopSet(SpanishAnalyzer.SPANISH_STOP_WORDS), new SpanishAnalyzer());
            }
            else
            {
                DocumenResult = moreLikeThisAnalyzer(original, Lucene.Net.Analysis.StopAnalyzer.ENGLISH_STOP_WORDS_SET, new StandardAnalyzer(Version.LUCENE_30));
            }

            //Convertir en UrlDocument para su procesamiento Web
            foreach (Document doc in DocumenResult)
            {
                UrlDocument UrlDoc = new UrlDocument();
                UrlDoc.Id                = doc.GetField("Id").StringValue;
                UrlDoc.Tittle            = doc.GetField("Title").StringValue;
                UrlDoc.URL               = doc.GetField("feed").StringValue;
                UrlDoc.Resume            = doc.GetField("Descripcion").StringValue;
                UrlDoc.Tags              = doc.GetField("Tags").StringValue;
                UrlDoc.Localizacion_name = doc.GetField("Location").StringValue;
                UrlDoc.Domain            = doc.GetField("Domain").StringValue;
                UrlDoc.Datastreams_feed  = doc.GetField("DataStreams").StringValue;
                UrlDoc.Website           = doc.GetField("Website").StringValue;
                UrlDoc.Elevacion         = doc.GetField("Elevacion").StringValue;
                UrlDoc.Latitud           = doc.GetField("Latitud").StringValue;
                UrlDoc.Longitud          = doc.GetField("Longitud").StringValue;

                //Campos propios de indexacion
                string listaconconceptos = doc.GetField("Conceptos").StringValue;
                UrlDoc.Conceptos = ConvertirenLista(listaconconceptos);

                UrlResult.Add(UrlDoc);
            }
            return(UrlResult);
        }
Esempio n. 4
0
        public async Task <ShortenResponseContract> HandleAsync(ShortenRequestContract contract, string sessionId)
        {
            var shortUrl = ShortenUrlHelper.GetRandomString();

            while (await _shortenerService.GetByShortUrl(shortUrl) != null)
            {
                shortUrl = ShortenUrlHelper.GetRandomString();
            }

            var doc = new UrlDocument
            {
                Created   = DateTime.UtcNow,
                SessionId = sessionId,
                LongUrl   = contract.LongUrl,
                ShortUrl  = shortUrl,
            };

            _shortenerService.SaveNewUrl(doc);

            return(new ShortenResponseContract
            {
                ShortUrl = shortUrl,
            });
        }
 public async void SaveNewUrl(UrlDocument doc)
 {
     await _urlCollection.InsertOneAsync(doc);
 }
        private Dictionary <string, UrlDocument> AnalizarDocumento(FeedXively feed)
        {
            Dictionary <string, UrlDocument> UrlResultTemp = new Dictionary <string, UrlDocument>();

            //RecolectorDocumentosXively recx;
            UrlDocument docLucene = new UrlDocument();

            //Obtiene el Id del feed como clave para el indice
            docLucene.Id  = feed.feed.id.ToString();
            docLucene.URL = feed.feed.feed.ToString();
            Trace.WriteLine("Creando Documento Lucene: " + docLucene.Id);

            //Obtiene el documento JSON original con etiquetas
            if (!string.IsNullOrEmpty(feed.DocumentJSON))
            {
                docLucene.DocumentUnParsed = feed.DocumentJSON;
            }
            //Relaciona los conceptos por los cuales que se encontró el documento en el servidor
            docLucene.Conceptos = feed.Conceptos;

            //Obtiene un resumen del Documento
            //documentResume = _HTMLParseManager.GetResume(documentParsed);
            if (!string.IsNullOrEmpty(feed.feed.description))
            {
                docLucene.Resume = feed.feed.description;
            }

            //Obtiene el Titulo del Documento
            if (!string.IsNullOrEmpty(feed.feed.title))
            {
                docLucene.Tittle = feed.feed.title;
            }

            //Obtiene las anotaciones
            if (feed.feed.tags != null)
            {
                StringBuilder builder = new StringBuilder();
                foreach (string tag in feed.feed.tags)
                {
                    builder.Append(tag).Append(" ");
                }
                docLucene.Tags = builder.ToString();
            }

            //Obtiene el sitio web de informacion adicional
            if (feed.feed.website != null)
            {
                docLucene.Website = feed.feed.website.ToString();
            }

            //Obtiene los datos de la localización
            if (feed.feed.location != null)
            {
                if (feed.feed.location.name != null)
                {
                    docLucene.Localizacion_name = feed.feed.location.name;
                }
                docLucene.Domain = feed.feed.location.domain.ToString();
                if (feed.feed.location.ele != null)
                {
                    docLucene.Elevacion = feed.feed.location.ele;
                }
                if (feed.feed.location.lat != null)
                {
                    docLucene.Latitud = feed.feed.location.lat;
                }
                if (feed.feed.location.lon != null)
                {
                    docLucene.Longitud = feed.feed.location.lon;
                }
            }

            //Obtiene una Lista de datastreams del feed en una cadena con el fin de darsela a Lucene para su indexación
            if (feed.feed.datastreams != null)
            {
                foreach (Datastream Dts in feed.feed.datastreams)
                {
                    docLucene.Datastreams_feed = Dts.id + " " + Dts.unit.symbol + " " + Dts.unit.label + " ";
                    string listatags = string.Empty;
                    if (Dts.tags != null)
                    {
                        foreach (string tg in Dts.tags)
                        {
                            listatags += "," + tg.ToString();
                        }
                    }
                    docLucene.Datastreams_feed = listatags;
                }
            }

            //Finalmente esta información se coloca en un solo string, pór posibles reusos
            string temp = string.Empty;

            if (!string.IsNullOrEmpty(docLucene.Resume))
            {
                temp = temp + " " + docLucene.Resume + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.Tittle))
            {
                temp = temp + " " + docLucene.Tittle + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.Tags))
            {
                temp = temp + " " + docLucene.Tags + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.Website))
            {
                temp = temp + " " + docLucene.Website + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.ConceptosLista()))
            {
                temp = temp + " " + docLucene.ConceptosLista() + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.Localizacion_name))
            {
                temp = temp + " " + docLucene.Localizacion_name + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.Domain))
            {
                temp = temp + " " + docLucene.Domain + " ";
            }
            if (!string.IsNullOrEmpty(docLucene.Datastreams_feed))
            {
                temp = temp + " " + docLucene.Datastreams_feed + " ";
            }
            docLucene.DocumentParsed = docLucene.DocumentParsed + " " + temp;

            //Estos datos no aportan a la búsqueda de texto por ello no se incluyen
            //docLucene.Elevacion + " " +
            //docLucene.Latitud + " " +
            //docLucene.Longitud + " " +

            //Pasamos aminusculas todo el texto ya que algunos campos no se analizaron
            docLucene.DocumentParsed = docLucene.DocumentParsed.ToLower();

            //Crear el diccionario de UrlResult analizados
            UrlResultTemp.Add(feed.feed.feed.ToString(), docLucene);


            return(UrlResultTemp);
        }
        private DataSet SearchSemanticIndex(string Consulta, string idioma)
        {
            //string idioma = ObtenerConfig("idiomaBusqueda");
            string expansion = ObtenerConfig("utilizarExpansion");

            //Crea el Objeto que guarda todo el conocimiento del negocio
            semanticIndexManager = new SemanticIndexManager();

            //Crea la lista de documentos que serán el resultado de la búsqueda
            List <UrlDocument> allReponse = new List <UrlDocument>();

            if (expansion == "Si")
            {
                //Realiza la expansión de la consulta a través del servicio.
                Consulta = ExpandirConsulta(Consulta, idioma);
            }

            //Se busca en español o el ingles. Si es nulo busca por ambos.
            if (idioma == "Español")
            {
                allReponse = semanticIndexManager.BuscarSemanticIndex(Consulta, true);
            }
            else if (idioma == "Ingles")
            {
                allReponse = semanticIndexManager.BuscarSemanticIndex(Consulta, false);
            }
            else
            {
                allReponse = semanticIndexManager.BuscarSemanticIndex(Consulta, true); //Por defecto busca español
            }
            //para DATASET que se devolvera como resultado
            UrlDocument objUrld = new UrlDocument();
            DataSet     nuevoDS = new DataSet();
            DataTable   table1  = new DataTable("Objetos Encontrados");

            table1.Columns.Add("Id");
            table1.Columns.Add("Title");
            table1.Columns.Add("Titulo_HTML");
            table1.Columns.Add("Url");
            table1.Columns.Add("URL_Sensor");
            table1.Columns.Add("Resumen");
            table1.Columns.Add("Tags");
            table1.Columns.Add("Localizacion");
            table1.Columns.Add("Dominio");
            table1.Columns.Add("Datastreams_feed");
            table1.Columns.Add("Website");
            table1.Columns.Add("Elevacion");
            table1.Columns.Add("Latitud");
            table1.Columns.Add("Longitud");
            //Campos para el PageRangkin
            table1.Columns.Add("Conceptos");   //Conceptos por los cuales fue encontrado en Xively
            table1.Columns.Add("Consulta");    //Consulta por la cual fue seleccionado el sensor
            table1.Columns.Add("Distancia");   //Distancia para efectos de un lugar específico
            table1.PrimaryKey = new DataColumn[] { table1.Columns["Id"] };

            foreach (UrlDocument urldoc in allReponse)
            {
                table1.Rows.Add(urldoc.Id, urldoc.Tittle, urldoc.TituloHTML(), urldoc.URL, urldoc.URLMostrar(), urldoc.Resume,
                                urldoc.Tags, urldoc.Localizacion_name, urldoc.Domain, urldoc.Datastreams_feed, urldoc.Website,
                                urldoc.Elevacion, urldoc.Latitud, urldoc.Longitud, urldoc.ConceptosLista(), Consulta);
            }

            nuevoDS.Tables.Add(table1);
            return(nuevoDS);
        }