Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCq1c-0004HF-M8 for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 21:40:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCq1Z-0002TK-Ce for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 21:40:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCq1Y-0002TA-WD for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 21:40:17 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nCq1T-0005sL-NI for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 21:40:16 +0000 Received: by mail-pj1-x1034.google.com with SMTP id g11-20020a17090a7d0b00b001b2c12c7273so3755206pjl.0 for ; Wed, 26 Jan 2022 13:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=oDQVVw3PnPo5XYBl8/AA/rpIvLZLI+paZ7hTYs97uGA=; b=YBtESeAAZJum+lTEOUfs39MV4ZqNll+rGdhN8p3enHV4qb4u3z4pbZC8pFaM9CC5i0 J8lPw3VOABcPKA73wqHEbJB275jCF7mjjkrFUCkDVYAwjzSLvC2GPAk82jJX07aNf0TB w17MXon0c9YINAxP9NdYvBANiFMVfo3zwSIspe2ItOn128zuiPCYKYQd/ABRBecLmMvN qNlGSxC8s27i4tfuQhJUAQ1sUiWxdzdTaf7zeR0Nu4Jm6kR6025tHEA46xDZIJSooW27 hBTa4hmCXxdVaGiMLqXuTejMlLAUpP6f7t5y79EE13YKAMYDahtiXHcpgBs5Zduqf+Hz FiiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=oDQVVw3PnPo5XYBl8/AA/rpIvLZLI+paZ7hTYs97uGA=; b=Q+XlhvZYjqeW8Q0FieAZbKGMD+bb8gdkGtGyEtbm/1caO79+zMqLEQ4V0XfP5JiOZk 7XpjlBzqICWU/bPevTqamTPRoetDjbAYjbhQpzIdA07wxHeoQxXqqgITAkRk29j1+mCm uPHJ/CZKdGWQr+YtMG/trYOHi9SqQJcsAhh8/XTfHa96I+o96fUpCRGy2STva130hQXI mgv2CO4YOZuh/G3gxGPqoG7eqPlVZ4KXqtS/MCCCML255f2tz440IKOzZjB/PlaTVL2v uj1nEmigEUP5jZ6G/UXe/2i7bq15LEhCjWcXon9BIxLL7Jd8Vh7/nbcje88MIGwbB3aI 2lwA== X-Gm-Message-State: AOAM533qwQvW49PgM90NxfB3t5x1HnouNgFHvmr6cWBgaMBL3sgEKlRm LOMnnDUHtk7K5yVF5o4CVoGr0oRNPkE= X-Google-Smtp-Source: ABdhPJweDSFPL87Zq3vq+PBGVxFz93gCOgbuR88N7Ds9Hic5SjPk+fiC694E4d/PFYkEBA7eu739+A== X-Received: by 2002:a17:902:e74a:: with SMTP id p10mr497691plf.16.1643233208984; Wed, 26 Jan 2022 13:40:08 -0800 (PST) Received: from [10.0.0.18] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id w10sm2782731pfn.153.2022.01.26.13.40.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jan 2022 13:40:08 -0800 (PST) Content-Type: multipart/alternative; boundary="------------AyavNJEQoOY8jVl9UBaB4oSE" Message-ID: <7f204b3c-3224-f8cb-a841-879f57ebf120@gmail.com> Date: Wed, 26 Jan 2022 14:40:07 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: Counting the number of repeated phrases in a column Content-Language: en-CA To: pgsql-general@lists.postgresql.org References: From: Rob Sargent In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------AyavNJEQoOY8jVl9UBaB4oSE Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/26/22 13:35, Shaozhong SHI wrote: > > > On Tue, 25 Jan 2022 at 17:10, Shaozhong SHI > wrote: > > There is a short of a function in the standard Postgres to do the > following: > > It is easy to count the number of occurrence of words, but it is > rather difficult to count the number of occurrence of phrases. > > For instance: > > A cell of value:  'Hello World' means 1 occurrence a phrase. > > A cell of value: 'Hello World World Hello' means no occurrence of > any repeated phrase. > > But, A cell of value: 'Hello World World Hello Hello World' means > 2 occurrences of 'Hello World'. > > 'The City of London, London' also has no occurrences of any > repeated phrase. > > Anyone has got such a function to check out the number of > occurrence of any repeated phrases? > > Regards, > > David > > > Hi, All Friends, > > Whatever.   Can we try to build a regex for   'The City of London > London Great London UK ' ? > > It could be something like '[\w\s]+[\s-]+[a-z]+[\s-][\s\w]+'. >  [\s-]+[a-z]+[\s-] is catered for some people think that 'City of > London' is 'City-of-London' or 'City-of-London'. > > Regards, > > David Do you really want "The City of", by itself, to be one of the detected phrases?  eg 'The City of London London Great London UK The City of Liverpool'. --------------AyavNJEQoOY8jVl9UBaB4oSE Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 1/26/22 13:35, Shaozhong SHI wrote:


On Tue, 25 Jan 2022 at 17:10, Shaozhong SHI <shishaozhong@gmail.com> wrote:
There is a short of a function in the standard Postgres to do the following:

It is easy to count the number of occurrence of words, but it is rather difficult to count the number of occurrence of phrases.

For instance:

A cell of value:  'Hello World' means 1 occurrence a phrase.

A cell of value: 'Hello World World Hello' means no occurrence of any repeated phrase.

But, A cell of value: 'Hello World World Hello Hello World' means 2 occurrences of 'Hello World'.

'The City of London, London' also has no occurrences of any repeated phrase.

Anyone has got such a function to check out the number of occurrence of any repeated phrases?

Regards,

David

Hi, All Friends,

Whatever.   Can we try to build a regex for   'The City of London London Great London UK ' ?

It could be something like '[\w\s]+[\s-]+[a-z]+[\s-][\s\w]+'.   [\s-]+[a-z]+[\s-] is catered for some people think that 'City of London' is 'City-of-London' or 'City-of-London'.

Regards,

David
Do you really want "The City of", by itself, to be one of the detected phrases?  eg 'The City of London London Great London UK The City of Liverpool'.
--------------AyavNJEQoOY8jVl9UBaB4oSE--