Python Forum
How to match partial sentence in long sentence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to match partial sentence in long sentence
#1
Hi,
I have below sentence and I want to check the sub-sentence (continuous appearance of words.

Example:
main_sentence= "The robot turn on and put on to machine AP0678A and started process IS=56"
sub_sentence = "put on to machine AP0678A and started process"
I use below code, but it is putting in every row

Code	    Status	                                     Rank
BA	        AA machine AP0678A process now	             2
BA	        The rob, fix AP0678A testing	             8
BA	        The initialize comp AP0678A start	         6
JK	        A machine PK0678A end vent ID=56	         23
JK	        The shutdown machine PK0678A test proc	     45
LP	        The machine UG5678A started coat	         9
LP	        The  re start UG5678A testing	             102
BA	        The  power on AP0678A  send report kit       563
import pandas as pd
df = pd.read_csv(r'D:\PythonCodes\machine2.csv')
df['final_status'] = 'NA'
for idx, row in df.iterrows():
    if "machine AP0678A processs" in row['Status']:
        df['final_status'] = 'AP0678A'
    elif "initialize comp AP0678A" in row['Status']:
        df['final_status'] = 'AP0678A'
    elif "comp AP0678A" in row['Status']:
        df['final_status'] = 'AP0678A'
    elif "power on AP0678A  send report" in row['Status']:
        df['final_status'] = 'AP0678A'
Code	    Status	                                         Rank  final_status
BA	        AA machine AP0678A process now	                 2     AP0678A    
BA	        The rob, fix AP0678A testing	                 8     AP0678A
BA	        The initialize comp AP0678A start	             6     AP0678A
JK	        A machine PK0678A end vent ID=56	             23    NA
JK	        The shutdown machine PK0678A test proc	         45    NA
LP	        The machine UG5678A started coat	             NA    NA
LP	        The  re start UG5678A testing	                 102   NA
BA	        The  power on AP0678A  send report kit           563   AP0678A
Reply
#2
It seems to me that extracting machine ID is simpler than trying to describe all possible statuses (machine ID starts with two capital letters, ends with capital letter and longer than 3; use stopwords for returning NA)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  partial functions before knowing the values mikisDeWitte 4 607 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Move Files based on partial Match mohamedsalih12 2 827 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Partial KEY search in dict klatlap 6 1,279 Mar-28-2023, 07:24 AM
Last Post: buran
  remove partial duplicates from csv ledgreve 0 789 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  Webhook, post_data, GPIO partial changes DigitalID 2 994 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  Optimal way to search partial correspondence in a large dict genny92c 0 1,003 Apr-22-2022, 10:20 AM
Last Post: genny92c
  Partial Matching Rows In Pandas DataFrame Query eddywinch82 1 2,378 Jul-08-2021, 06:32 PM
Last Post: eddywinch82
  while sentence kimyyya 3 2,956 Mar-20-2021, 06:00 AM
Last Post: Pedroski55
  List / arrays putting in sentence Kurta 3 2,573 Dec-25-2020, 11:29 AM
Last Post: Larz60+
  How to make a telegram bot respond to the specific word in a sentence? Metodolog 2 6,368 Dec-22-2020, 07:30 AM
Last Post: martabassof

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020