]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text.hs
[TERMS] main function.
[gargantext.git] / src / Gargantext / Text.hs
1 {-|
2 Module : Gargantext.Text
3 Description : Ngrams tools
4 Copyright : (c) CNRS, 2018
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Text gathers terms in unit of contexts.
11
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16
17 module Gargantext.Text
18 where
19
20 import qualified Data.Text as DT
21 --import Data.Text.IO (readFile)
22
23
24 import Data.Text (Text, split)
25
26 import NLP.FullStop (segment)
27 -----------------------------------------------------------------
28
29 import Gargantext.Core.Types
30 import Gargantext.Prelude hiding (filter)
31 -----------------------------------------------------------------
32
33 data Group = Group { _group_label :: Terms
34 , _group_terms :: Terms
35 } deriving (Show)
36
37
38 -------------------------------------------------------------------
39 -- Contexts of text
40 sentences :: Text -> [Text]
41 sentences txt = map DT.pack $ segment $ DT.unpack txt
42
43 sentences' :: Text -> [Text]
44 sentences' txt = split isStop txt
45
46 isStop :: Char -> Bool
47 isStop c = c `elem` ['.','?','!']
48
49 unsentences :: [Text] -> Text
50 unsentences txts = DT.intercalate " " txts
51
52 -- | https://en.wikipedia.org/wiki/Text_mining
53 testText_en :: Text
54 testText_en = DT.pack "Text mining, also referred to as text data mining, roughly equivalent to text analytics, is the process of deriving high-quality information from text. High-quality information is typically derived through the devising of patterns and trends through means such as statistical pattern learning. Text mining usually involves the process of structuring the input text (usually parsing, along with the addition of some derived linguistic features and the removal of others, and subsequent insertion into a database), deriving patterns within the structured data, and finally evaluation and interpretation of the output. 'High quality' in text mining usually refers to some combination of relevance, novelty, and interestingness. Typical text mining tasks include text categorization, text clustering, concept/entity extraction, production of granular taxonomies, sentiment analysis, document summarization, and entity relation modeling (i.e., learning relations between named entities). Text analysis involves information retrieval, lexical analysis to study word frequency distributions, pattern recognition, tagging/annotation, information extraction, data mining techniques including link and association analysis, visualization, and predictive analytics. The overarching goal is, essentially, to turn text into data for analysis, via application of natural language processing (NLP) and analytical methods. A typical application is to scan a set of documents written in a natural language and either model the document set for predictive classification purposes or populate a database or search index with the information extracted."
55
56 -- | https://fr.wikipedia.org/wiki/Fouille_de_textes
57 testText_fr :: Text
58 testText_fr = DT.pack "La fouille de textes ou « l'extraction de connaissances » dans les textes est une spécialisation de la fouille de données et fait partie du domaine de l'intelligence artificielle. Cette technique est souvent désignée sous l'anglicisme text mining. Elle désigne un ensemble de traitements informatiques consistant à extraire des connaissances selon un critère de nouveauté ou de similarité dans des textes produits par des humains pour des humains. Dans la pratique, cela revient à mettre en algorithme un modèle simplifié des théories linguistiques dans des systèmes informatiques d'apprentissage et de statistiques. Les disciplines impliquées sont donc la linguistique calculatoire, l'ingénierie des langues, l'apprentissage artificiel, les statistiques et l'informatique."
59
60 -- | Ngrams Test
61 -- >>> ngramsTest testText
62 -- 248
63 --ngramsTest :: Text -> Int
64 --ngramsTest x = length ws
65 -- where
66 -- --txt = concat <$> lines <$> clean <$> readFile filePath
67 -- txt = clean x
68 -- -- | Number of sentences
69 -- --ls = sentences $ txt
70 -- -- | Number of monograms used in the full text
71 -- ws = ngrams $ txt
72 -- -- | stem ngrams
73 -- TODO
74 -- group ngrams
75 --ocs = occ $ ws
76