#đź”’ Help with parsing and structuring data

119 messages · Page 1 of 1 (latest)

bronze pecan
#

If I have a JSON of scraped listing of laptops, but the descriptions were messy, how can I reliably extract specs, model name, CPU etc from the listing?

pearl loomBOT
#

@bronze pecan

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

bronze pecan
#

Example data:

pearl loomBOT
bronze pecan
#

It must also delete listings which have insufficient information

clear osprey
#

!e You could do something like this:

import re

description = "Apple MacBook Air 13.3\" (2017) – i5 – 8GB RAM – 256GB SSD – inkl. OVP & Original Ladegerät✅ Generalüberholt & sofort einsatzbereitZuverlässiges und leichtes Apple MacBook Air – ideal für Studium, Office, Surfen & Alltag.✔ Generalüberholt & vollständig geprüft✔ macOS Monterey frisch installiert✔ Sofort startklar – kein Setup nötig✔ 1 Jahr Gewährleistung✔ Rechnung inklusive✔ Original Apple Ladegerät inklusive✔ Originalverpackung (OVP) enthalten⚡ Leistungsstarke AusstattungIntel Core i5 Dual-Core (1,8 GHz)8GB RAM256GB SSD (schnell & zuverlässig)Intel HD Graphics 6000️ Display & Design13,3 Zoll Display1440 x 900 Pixelkompakt, leicht & ideal für unterwegsAnschlüsse & KonnektivitätThunderbolt 2 (Mini DisplayPort)2x USB 3.0SDXC KartenleserMagSafe 2 LadeanschlussWLAN (ac) & Bluetooth 4.0Akku✔ Zustand: Gut (laut Apple System)solide Laufzeit für den "

cpu = re.search(r"(i5|i3|i7)", description)
if cpu: print(cpu.group(0))

ram = re.search(r"(\d+\s*GB)\s*RAM", description)
if ram: print(ram.group(0))

ssd = re.search(r"(\d+\s*GB)\s*SSD", description)
if ssd: print(ssd.group(0))
pearl loomBOT
clear osprey
#

I notice that each section is also separated by a special character, so maybe you could split on – first, and then do checks.

#

!e like this:

description = "Apple MacBook Air 13.3\" (2017) – i5 – 8GB RAM – 256GB SSD – inkl. OVP & Original Ladegerät✅ Generalüberholt & sofort einsatzbereitZuverlässiges und leichtes Apple MacBook Air – ideal für Studium, Office, Surfen & Alltag.✔ Generalüberholt & vollständig geprüft✔ macOS Monterey frisch installiert✔ Sofort startklar – kein Setup nötig✔ 1 Jahr Gewährleistung✔ Rechnung inklusive✔ Original Apple Ladegerät inklusive✔ Originalverpackung (OVP) enthalten⚡ Leistungsstarke AusstattungIntel Core i5 Dual-Core (1,8 GHz)8GB RAM256GB SSD (schnell & zuverlässig)Intel HD Graphics 6000️ Display & Design13,3 Zoll Display1440 x 900 Pixelkompakt, leicht & ideal für unterwegsAnschlüsse & KonnektivitätThunderbolt 2 (Mini DisplayPort)2x USB 3.0SDXC KartenleserMagSafe 2 LadeanschlussWLAN (ac) & Bluetooth 4.0Akku✔ Zustand: Gut (laut Apple System)solide Laufzeit für den "

parts = description.split(' – ')
print(*parts[:4], sep='\n')
pearl loomBOT
clear osprey
#

@bronze pecan ?

bronze pecan
#

I want to be able to get the exact model name, screen size (if provided), ram, GPU, CPU, storage, model year and write it all into a JSON file

ionic thistle
#

hello

short patrol
ionic thistle
#

neither will work, unless you have a RAG with a database of every model of laptop that has ever been made

bronze pecan
#

That's a part of my project

bronze pecan
#

I know how to build RAG

#

And how it works

#

And I don't need every listing of every laptop ever made

ionic thistle
#

there is no way you can get clean data out of a dataset that is so inconsistent, because at some point you are going to run into titles that even humans cannot find the model for

bronze pecan
#

Just ones > 2015

short patrol
# bronze pecan Well I need to parse

well you've mentioned the problem. Its not consistently reliable to detect a pattern on how people enters their title and description into their ad.

bronze pecan
ionic thistle
#

at some point even a human won't be able to tell

brisk salmon
#

depending on how many listings you've got (and if you only have to do it once), classifying them manually is also an option... It is painful, but I've done it before for stuff like this

bronze pecan
#

Cause it doesn't mention model name

#

And only the brand name

#

I was thinking of keeping a hierarchy list

ionic thistle
bronze pecan
#

Can't do it manually

ionic thistle
#

imagine if i had a laptop listing for "Acer 4736G"

#

i misspell it, and i get "Acer 4737G", a model which does not exist

#

does it filter it out?

bronze pecan
brisk salmon
ionic thistle
bronze pecan
ionic thistle
bronze pecan
#

That's a low quality entry

bronze pecan
#

Or ones that actually exist

ionic thistle
#

how about small typos like "Ac er"

bronze pecan
#

It'll accept a cer, ac er, or ace r

ionic thistle
#

even then, how do you tell if the model number is correct to the specifications

ionic thistle
#

what if i were to show up with a macbook air 11 with an AMD 9800x3d

#

macbook air 11 exists

#

AMD 9800x3d exists

bronze pecan
#

That's a low quality entry, instantly deleted

ionic thistle
#

where did you get this info from?

bronze pecan
ionic thistle
#

you as a human know this

#

but how does the computer tell?

bronze pecan
ionic thistle
bronze pecan
#

That would account for maybe 1%

ionic thistle
#

was there ever HP G32 with an Intel 1145G7?

ionic thistle
#

you underestimate how much humans misspell model names

bronze pecan
#

I don't want it to be perfect, just good enough that it can account for 90% at least

ionic thistle
#

but to get to 90% is already a problem in of itself

bronze pecan
#

Etc

#

Simple names

bronze pecan
#

It's hard to get them incorrect

ionic thistle
#

you can regex for the common stuff like i3, i5, i7, ryzen 5, ryzen 7 etc

bronze pecan
#

I have that down

#

The only problem is the model names

ionic thistle
#

hmm

bronze pecan
#

I can't seem to find a good method for extracting that

#

Do you have any ideas 🥲

ionic thistle
#

checking

ionic thistle
#

you can probably get to 90% with just the major laptop manufacturers

ionic thistle
#

acer, asus, hp, dell, etc

ionic thistle
bronze pecan
ionic thistle
#

i dont know if this will work, and i can't help with that

bronze pecan
#

So I get all the model names and then maintain a herirarchy table

ionic thistle
bronze pecan
#

And check if those keywords appear in the title/description

#

And assign the model_namw accordingly?

ionic thistle
#

because this dataset is so inconsistent, i would not be able to tell the effectiveness of this method

#

with this database of model names, you can use a RAG but obviously regex will be WAY faster

#

and accurate

bronze pecan
short patrol
#

Alternatively, could use Amazon Product Search API, refine the search down to just Electronics > Computers, and fetch all entered keywords and descriptions and specs from there...

bronze pecan
#

If I can find documents on the internet that has model names of most major laptop companies

#

Or collect them

#

Is it better to use RAG?

bronze pecan
#

I think that's a good idea too

short patrol
bronze pecan
short patrol
#

At least referring from the direct source, its a lot more up to date than getting from some intermediary API

bronze pecan
#

I think I should have multiple fallbacks

short patrol
short patrol
#

fetching for missing info from current discontinued models will likely be manually be done. A quick google here and there, update it in your DB directly and thats it.

pearl loomBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.