رفتن به مطلب

چطور کل کلمات یه متن را در قالب یک array استخراج کنیم


پست های پیشنهاد شده

لازم دارم کل کلمات به متن رو استخراج کنم و بعد بررسی کنم که ایا این کلمات توی دیتابیس من موجود هستن یا ن و الی آخر

اما توی مرحله استخراج لغات گیر کردم (لغات انگلیسی هستن) خب من اول اومدم کد زیر رو امتحان کردم

preg_match_all("~([\w]+)~", $text,$words);

خیلی خوب کار کرد تا مشکلی که داشت این بود که لغاتی مثل can’t را دو لغت حساب میکرد (به این صورت: لغت اول: can لغت دوم: t) 

من اومدم کد رو شکل زیر تغییر دادم:

preg_match_all("~([\w\’]+)~", $text,$words);

اما مشکلی که داشت بعضی کلمات که بلافاصله بعدشون نقطه یا کاما بود رو اشتباه نشون میداد مثلا به جای minds یکی از عضو های array 

minds�

هست چندین تا لغت دیگه هم به همین شکل یه کاراکتر � اضافی به تهشون اضافه شده

چه کار کنیم که این مشکل پیش نیاد؟ اصلا دلیل اتفاق افتادن این پدیده چیه؟

 

نمونه ای از متن مد نظرم:

Procrastination comes in many disguises. We might resolve to tackle a task, but find endless reasons to defer it. We might prioritize things we can readily tick off our to-do list—answering emails, say—while leaving the big, complex stuff untouched for another day. We can look and feel busy, while artfully avoiding the tasks that really matter. And when we look at those rolling, long-untouched items at the bottom of our to-do list, we can’t help but feel a little disappointed in ourselves.

The problem is our brains are programmed to procrastinate. In general, we all tend to struggle with tasks that promise future upside in return for efforts we take now. That’s because it’s easier for our brains to process concrete rather than abstract things, and the immediate hassle is very tangible compared with those unknowable, uncertain future benefits. So the short-term effort easily dominates the long-term upside in our minds—an example of something that behavioral scientists call present bias.

How can you become less myopic about your elusive tasks? It’s all about rebalancing the cost-benefit analysis: make the benefits of action feel bigger, and the costs of action feel smaller. The reward for doing a pestering task needs to feel larger than the immediate pain of tackling it.

To make the benefits of action feel bigger and more real:

Visualize how great it will be to get it done. Researchers have discovered that people are more likely to save for their future retirement if they’re shown digitally aged photographs of themselves. Why? Because it makes their future self feel more real—making the future benefits of saving also feel more weighty. When we apply a lo-fi version of this technique to any task we’ve been avoiding, by taking a moment to paint ourselves a vivid mental picture of the benefits of getting it done, it can sometimes be just enough to get us unstuck. So if there’s a call you’re avoiding or an email you’re putting off, give your brain a helping hand by imagining the virtuous sense of satisfaction you’ll have once it’s done—and perhaps also the look of relief on someone’s face as they get from you what they needed.

Pre-commit, publicly. Telling people that we’re going to get something done can powerfully amplify the appeal of actually taking action, because our brain’s reward system is so highly responsive to our social standing. Research has found that it matters greatly to us whether we’re respected by others—even by strangers. Most of us don’t want to look foolish or lazy to other people. So by daring to say “I’ll send you the report by the end of the day” we add social benefits to following through on our promise—which can be just enough to nudge us to bite the bullet.

 

 

لینک به ارسال

میخوام کللن مشکلی توی شناخت و استخراج لغات مختلف یه متن استاندارد انگلیسی نداشته باشه

مورد دیگه هم که هست میخوام لغاتی مثل Pre-commit و to-do رو هم هر کدوم رو یه لغت حساب کنه نه هر کدوم رو دو لغت

لینک به ارسال

میتونین از کد زیر استفاده کنید

$str = "hello i'm student and co-worker.i live in iran";
$arr = preg_split('/[\s|\.|,]/',$str);
var_dump($arr);

 

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...