Create an account


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 20,122
» Latest member: jax9090nn
» Forum threads: 21,748
» Forum posts: 22,617

Full Statistics

Online Users
There are currently 1095 online users.
» 1 Member(s) | 1090 Guest(s)
Applebot, Baidu, Bing, Google, jax9090nn

 
  [Oracle Blog] Java Client Roadmap Updates
Posted by: xSicKxBot - 12-14-2022, 01:24 PM - Forum: Java Language, JVM, and the JRE - No Replies

Java Client Roadmap Updates

Oracle has published an update to the Java Client Roadmap which extends availability and support timelines for many Java Client related technologies. Executive Summary: Oracle has extended commercial support and updates for Java SE 8 from March 2025 to at least December 2030. Oracle has extended ind...


https://blogs.oracle.com/java/post/java-...ap-updates

Print this item

  [Tut] Python | Split Text into Sentences
Posted by: xSicKxBot - 12-14-2022, 01:24 PM - Forum: Python - No Replies

Python | Split Text into Sentences

Rate this post

✨Summary: There are four different ways to split a text into sentences:
? Using nltk module
? Using re.split()
? Using re.findall()
? Using replace

Minimal Example


text = "God is Great! I won a lottery." # Method 1
from nltk.tokenize import sent_tokenize
print(sent_tokenize(text)) # Method 2
import re
res = [x for x in re.split("[//.|//!|//?]", text) if x!=""]
print(res) # Method 3
res = re.findall(r"[^.!?]+", text)
print(res) # Method 4
def splitter(txt, delim): for i in txt: if i in delim: txt = txt.replace(i, ',') res = txt.split(',') res.pop() return res sep = ['.', '!']
print(splitter(text, sep)) # Output: ['God is Great', ' I won a lottery']

Problem Formulation


Problem: Given a string/text containing numerous sentences; How will you split the string into sentences?

Example: Let’s visualize the problem with the help of an example.

# Input
text = "This is sentence 1. This is sentence 2! This is sentence 3?"
# output
['This is sentence 1', ' This is sentence 2', ' This is sentence 3']

Method 1: Using nltk.tokenize


Natural Language Processing (NLP) has a process known as tokenization using which a large quantity of text can be divided into smaller parts called tokens. The Natural Language toolkit contains a very important module known as NLTK tokenize sentence which further comprises sub-modules. We can use this module and split a given text into sentences.

Code:

from nltk.tokenize import sent_tokenize
text = "This is sentence 1. This is sentence 2! This is sentence 3?"
print(sent_tokenize(text)) # ['This is sentence 1.', ' This is sentence 2!', ' This is sentence 3?']

Explanation: 

  • Import the sent_tokenize module.
  • Further, the sentence_tokenizer module allows you to parse the given sentences and break them into individual sentences at the occurrence of punctuations like periods, exclamation,  question marks, etc.

Caution: You might get an error after installing the nltk package. So, here’s the entire process to install nltk in your system.

Install nltk using → pip install nltk

Then go ahead and type the following in your Python shell:

import nltk
nltk.download('punkt')

That’s it! You are now ready to use the sentence_tokenizer module in your code.

Method 2: Using re.split


The re.split(pattern, string) method matches all occurrences of the pattern in the string and divides the string along the matches resulting in a list of strings between the matches. For example, re.split('a', 'bbabbbab') results in the list of strings ['bb', 'bbb', 'b'].

Approach: Split the given string using alphanumeric separators, and use the either-or (|) metacharacter. It allows you to specify each separator within the expression like so: re.split("[//.|//!|//?]", text). Thus, whenever the script encounters any of the mentioned characters specified within the pattern, it will split the given string. The expression x!="" ignores all the empty characters.

Code:

import re
text = "This is sentence 1. This is sentence 2! This is sentence 3?"
res = [x for x in re.split("[//.|//!|//?]", text) if x!=""]
print(res) # ['This is sentence 1', ' This is sentence 2', ' This is sentence 3']

?Recommended Read:  Python Regex Split

Method 3: Using findall


The re.findall(pattern, string) method scans the string from left to right, searching for all non-overlapping matches of the pattern. It returns a list of strings in the matching order when scanning the string from left to right.

Code:

import re
text = "This is sentence 1. This is sentence 2! This is sentence 3?"
res = re.findall(r"[^.!?]+", text)
print(res) # ['This is sentence 1', ' This is sentence 2', ' This is sentence 3']

Explanation: In the expression, i.e., re.findall(r"[^.!?]+", text), all occurrences of characters are grouped except the punctuation marks. []+ denotes that all occurrences of one or more characters except (given by ^) ‘!’, ‘?’, and ‘.’ will be returned. Thus, whenever the script finds and groups all characters until any of the mentioned characters within the square brackets are found. As soon as one of the mentioned characters is found it splits the string and finds the next group of characters.

?Related Read: Python re.findall() – Everything You Need to Know

Method 4: Using replace


Approach: The idea here is to replace all the punctuation marks (‘!’, ‘?’, and ‘.’) present in the given string with a comma (,) and then split the modified string to get the list of split substrings. The problem here is the last element returned will be an empty string. You can use the pop() method to remove the last element out of the list of substrings (the empty string).

Code:

def splitter(txt, delim): for i in txt: if i in delim: txt = txt.replace(i, ',') res = txt.split(',') res.pop() return res sep = ['.', '!', '?']
text = "This is sentence 1. This is sentence 2! This is sentence 3?"
print(splitter(text, sep)) # ['This is sentence 1', ' This is sentence 2', ' This is sentence 3']

?Related Read: Python String replace()

Conclusion


We have successfully solved the given problem using different approaches. I hope this article helped you in your Python coding journey. Please subscribe and stay tuned for more interesting articles.

Happy coding! ?


Do you want to master the regex superpower? Check out my new book The Smartest Way to Learn Regular Expressions in Python with the innovative 3-step approach for active learning: (1) study a book chapter, (2) solve a code puzzle, and (3) watch an educational chapter video.



https://www.sickgaming.net/blog/2022/12/...sentences/

Print this item

  (Indie Deal) Monster Spark Bundle & Black Friday are officially here
Posted by: xSicKxBot - 12-14-2022, 01:24 PM - Forum: Deals or Specials - No Replies

Monster Spark Bundle & Black Friday are officially here

Monster Spark Bundle | 6 Steam Games | 95% OFF
[www.indiegala.com]
All you need is that one spark to unleash the monster in you, one that will enjoy a video game experience like never before: DwarfHeim, RIOT: Civil Unrest, The Long Reach, Sparklite, Mainlining Deluxe Edition, Monster Harvest.

Black Friday is here...officially!
[www.indiegala.com]
Extra 10% cashback as a BONUS in this period only!
https://www.youtube.com/watch?v=5B3fuoNaoj4
Tales of Giveaways
[www.indiegala.com]


https://steamcommunity.com/groups/indieg...9740505321

Print this item

  (Free Game Key) 4 Steam Freebies (DLCs and +1 Games)
Posted by: xSicKxBot - 12-14-2022, 01:24 PM - Forum: Deals or Specials - No Replies

4 Steam Freebies (DLCs and +1 Games)

Divine Knockout DKO
(for some reason this game says its a free 2 play game, but it costs money)
Activating the game this way will add +1 to your account, just click Install
Store Page

Capcom Arcade Stadium:FINAL FIGHT
This is a dlc for Capcom Arcade (f2p)
First activate
Capcom Arcade
Then Activate the DLC Final Fight

World of Warships New Year Camo
World of Warship - activate the base game first
New Year Camo Collection

World of Tanks Holiday Gift Pack
World of Tanks - activate the base game first
Holiday Gift Pack

We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...3044991668

Print this item

  PC - World of Warcraft: Dragonflight
Posted by: xSicKxBot - 12-14-2022, 01:24 PM - Forum: New Game Releases - No Replies

World of Warcraft: Dragonflight



The dragonflights of Azeroth have returned, called upon to defend their ancestral home, the Dragon Isles. Surging with elemental magic and the life energies of Azeroth, the Isles are awakening once more, and it's up to you to explore their primordial wonder and discover long-forgotten secrets.

Publisher: Activision

Release Date: Nov 28, 2022




https://www.metacritic.com/game/pc/world...agonflight

Print this item

  [Oracle Blog] Our World. Moved by Java.
Posted by: xSicKxBot - 12-13-2022, 06:04 AM - Forum: Java Language, JVM, and the JRE - No Replies

Our World. Moved by Java.

Authored by: Georges Saab (VP, Java Platform Group and Chair, OpenJDK Governing Board) It is hard to believe that it has been 25 years since Java became officially available. On the other hand, it seems like several eras have passed - and in some sense, they have. I still remember the sense of excit...


https://blogs.oracle.com/java/post/our-w...ed-by-java

Print this item

  [Tut] Python | Split String with Regex
Posted by: xSicKxBot - 12-13-2022, 06:04 AM - Forum: Python - No Replies

Python | Split String with Regex

Rate this post

Summary: The different methods to split a string using regex are:

  • re.split()
  • re.sub()
  • re.findall()
  • re.compile()

Minimal Example


import re text = "Earth:Moon::Mars:Phobos" # Method 1
res = re.split("[:]+", text)
print(res) # Method 2
res = re.sub(r':', " ", text).split()
print(res) # Method 3
res = re.findall("[^:\s]+", text)
print(res) # Method 4
pattern = re.compile("[^:\s]+").findall
print(pattern(text)) # Output
['Earth', 'Moon', 'Mars', 'Phobos']

Problem Formulation


?Problem: Given a string and a delimiter. How will you split the string using the given delimiter using different functions from the regular expressions library?

Example: In the following example, the given string has to be split using a hyphen as the delimiter.

# Input
text = "abc-lmn-xyz" # Expected Output
['abc', 'lmn', 'xyz']

Method 1: re.split


The re.split(pattern, string) method matches all occurrences of the pattern in the string and divides the string along the matches resulting in a list of strings between the matches. For example, re.split('a', 'bbabbbab') results in the list of strings ['bb', 'bbb', 'b'].


Approach: Use the re.split function and pass [_]+ as the pattern which splits the given string on occurrence of an underscore.

Code:

import re text = "abc_lmn_xyz"
res = re.split("[_]+", text)
print(res) # ['abc', 'lmn', 'xyz']

?Related Read: Python Regex Split

Method 2: re.sub


The regex function re.sub(P, R, S) replaces all occurrences of the pattern P with the replacement R in string S. It returns a new string. For example, if you call re.sub('a', 'b', 'aabb'), the result will be the new string 'bbbb' with all characters 'a' replaced by 'b'.


Approach: The idea here is to use the re.sub function to replace all occurrences of underscores with a space and then use the split function to split the string at spaces.

Code:

import re text = "abc_lmn_xyz"
res = re.sub(r'_', " ", text).split()
print(res) # ['abc', 'lmn', 'xyz']

?Related Read: Python Regex Sub

Method 3: re.findall


The re.findall(pattern, string) method scans string from left to right, searching for all non-overlapping matches of the pattern. It returns a list of strings in the matching order when scanning the string from left to right.


Approach: Find all occurrences of characters that are separated by underscores using the re.findall().

Code:

import re text = "abc_lmn_xyz"
res = re.findall("[^_\s]+", text)
print(res) # ['abc', 'lmn', 'xyz']

?Related Read: Python re.findall()

Method 4: re.compile


The method re.compile(pattern) returns a regular expression object from the pattern that provides basic regex methods such as pattern.search(string)pattern.match(string), and pattern.findall(string). The explicit two-step approach of (1) compiling and (2) searching the pattern is more efficient than calling, say, search(pattern, string) at once, if you match the same pattern multiple times because it avoids redundant compilations of the same pattern.


Code:

import re text = "abc_lmn_xyz"
pattern = re.compile("[^-\s]+").findall
print(pattern(text)) # ['abc', 'lmn', 'xyz']

Why use re.compile?


  • Efficiency: Using re.compile() to assemble regular expressions is effective when the expression has to be used more than once. Thus, by using the classes/objects created by compile function, we can search for instances that we need within different strings without having to rewirte the expressions again and again. This increases productivity as well as saves time.
  • Readability: Another advantage of using re.compile is the readability factor as it leverages you the power to decouple the specification of the regex.

?Read: Is It Worth Using Python’s re.compile()?

Exercise


Problem: Python regex split by spaces, commas, and periods, but not in cases like 1,000 or 1.50.

Given:
my_string = "one two 3.4 5,6 seven.eight nine,ten"
Expected Output:
["one", "two", "3.4", "25.6" , "seven", "eight", "nine", "ten"]

Solution

my_string = "one two 3.4 25.6 seven.eight nine,ten"
res = re.split('\s|(?<!\d)[,.](?!\d)', my_string)
print(res) # ['one', 'two', '3.4', '25.6', 'seven', 'eight', 'nine', 'ten']

Conclusion


Therefore, we have learned four different ways of splitting a string using the regular expressions package in Python. Feel free to use the suitable technique that fits your needs. The idea of this tutorial was to get you acquainted with the numerous ways of using regex to split a string and I hope it helped you.

Please stay tuned and subscribe for more interesting discussions and tutorials in the future. Happy coding! ?


Do you want to master the regex superpower? Check out my new book The Smartest Way to Learn Regular Expressions in Python with the innovative 3-step approach for active learning: (1) study a book chapter, (2) solve a code puzzle, and (3) watch an educational chapter video.



https://www.sickgaming.net/blog/2022/12/...ith-regex/

Print this item

  (Indie Deal) PJ Sam & Golazo Giveaways, Neptunuia & TMNT Deals
Posted by: xSicKxBot - 12-13-2022, 06:04 AM - Forum: Deals or Specials - No Replies

PJ Sam & Golazo Giveaways, Neptunuia & TMNT Deals

Pajama Sam & Golazo Giveaways
[www.indiegala.com]
https://www.youtube.com/watch?v=8uOX4rDyXBI
Idea Factory Sale, up to 80% OFF
[www.indiegala.com]
https://www.youtube.com/watch?v=9pHFNsBuA28
https://www.youtube.com/watch?v=1kPdvJWhXAA
[discord.gg]


https://steamcommunity.com/groups/indieg...3313485452

Print this item

  (Free Game Key) Ghost of a tale - Free GOG Game Giveaway
Posted by: xSicKxBot - 12-13-2022, 06:04 AM - Forum: Deals or Specials - No Replies

Ghost of a tale - Free GOG Game Giveaway

This giveaway is on gog.com gog is a platform for games that is dedicated to drm-free games (those are games that do not require login or registration to play the game)

How to grabGhost of a tale
- Go to the home page of https://gog.com/#giveaway
- Login and Register
- Go to the home page again
- Wait for 10 seconds then start searching for Ghost of a tale
- on the home page look for "Deal of the Day" (above it there should be a banner)
- on the banner there is a button "Yes, and claim the game" click it
- Thats it


GOG Store link: https://www.gog.com/game/ghost_of_a_tale
Auto-claim link: https://www.gog.com/giveaway/claim

We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...3054866631

Print this item

  News - Elden Ring: Where To Get The Coil Shield
Posted by: xSicKxBot - 12-13-2022, 06:04 AM - Forum: Lounge - No Replies

Elden Ring: Where To Get The Coil Shield

Though you can technically use them to deal damage, most shields in Elden Ring are, well, meant for doing things shields tend to do, like blocking and parrying. In the case of the Coil Shield, though, there's a very special skill attached that can be a lot of fun for poison-based builds--and it looks cool to boot. If that sounds fun to you, read on to find out where you can pick it up.

The Coil Shield explained

The Coil Shield is a small shield that requires 10 Strength and 10 Dexterity to wield. Its unique weapon skill is Viper Bite, which can be activated to deal a bit of damage and inflict poison buildup on enemies, making it a truly unique shield.

The Coil Shield's item description reads:

Continue Reading at GameSpot

https://www.gamespot.com/articles/elden-...01-10abi2f

Print this item

 
Latest Threads
RebatesMe Fashion Deals F...
Last Post: albert42
1 hour ago
RebatesMe Coupon Code $5 ...
Last Post: albert42
1 hour ago
RebatesMe Sign-Up Bonus C...
Last Post: albert42
1 hour ago
RebatesMe Electronics Dea...
Last Post: albert42
1 hour ago
Black Ops (BO1, T5) DLC's...
Last Post: gottaluvthatkill
1 hour ago
Black Ops (BO1, T5) DLC's...
Last Post: gottaluvthatkill
1 hour ago
RebatesMe Food Deals 8% C...
Last Post: albert42
1 hour ago
New RebatesMe Code [OO8EI...
Last Post: albert42
1 hour ago
Forza Horizon 5 Game Save...
Last Post: Vecanoidal
1 hour ago
RebatesMe Invite Code [OO...
Last Post: albert42
1 hour ago

Forum software by © MyBB Theme © iAndrew 2016