Support
Quality
Security
License
Reuse
kandi has reviewed Luban and discovered the below as its top functions. This is intended to give you an instant insight into Luban implemented functionality, and help decide if they suit your requirements.
Luban(鲁班)—Image compression with efficiency very close to WeChat Moments/可能是最接近微信朋友圈的图片压缩算法
导入
implementation 'top.zibin:Luban:1.1.8'
异步调用
Luban.with(this)
.load(photos)
.ignoreBy(100)
.setTargetDir(getPath())
.filter(new CompressionPredicate() {
@Override
public boolean apply(String path) {
return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif"));
}
})
.setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
// TODO 压缩开始前调用,可以在方法内启动 loading UI
}
@Override
public void onSuccess(File file) {
// TODO 压缩成功后调用,返回压缩后的图片文件
}
@Override
public void onError(Throwable e) {
// TODO 当压缩过程出现问题时调用
}
}).launch();
同步调用
Flowable.just(photos)
.observeOn(Schedulers.io())
.map(new Function<List<String>, List<File>>() {
@Override public List<File> apply(@NonNull List<String> list) throws Exception {
// 同步方法直接返回压缩后的文件
return Luban.with(MainActivity.this).load(list).get();
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
License
Copyright 2016 Zheng Zibin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
How to extract a human name in a string python
[:;]\s*(.+?)\s*<
import re
s = """From: Al Amri, Salim <salim.amri@gmail.com>
Sent: 25 August 2021 17:20
To: Al Harthi, Mohammed <mohd4.king@rihal.om>
Ce: Al hajri, Malik <hajri990@ocaa.co.om>; Omar, Naif <nnnn49@apple.com>
Subject: Conference Rooms Booking Details
Dear Mohammed,
As per our last discussion these are the available conference rooms available for booking along
with their rates for full day:
Room: Luban, available on 26/09/2021. Rate: $4540
Room: Mazoon, available on 04/12/2021 and 13/02/2022. Rate: $3000
Room: Dhofar. Available on 11/11/2021. Rate: $2500
Room: Nizwa. Available on 13/12/2022. Rate: $1200
Please let me know which ones you are interested so we go through more details.
Best regards,
Salim Al Amri"""
print(re.findall(r'[:;]\s*(.+?)\s*<', s))
['Al Amri, Salim', 'Al Harthi, Mohammed', 'Al hajri, Malik', 'Omar, Naif']
-----------------------
[:;]\s*(.+?)\s*<
import re
s = """From: Al Amri, Salim <salim.amri@gmail.com>
Sent: 25 August 2021 17:20
To: Al Harthi, Mohammed <mohd4.king@rihal.om>
Ce: Al hajri, Malik <hajri990@ocaa.co.om>; Omar, Naif <nnnn49@apple.com>
Subject: Conference Rooms Booking Details
Dear Mohammed,
As per our last discussion these are the available conference rooms available for booking along
with their rates for full day:
Room: Luban, available on 26/09/2021. Rate: $4540
Room: Mazoon, available on 04/12/2021 and 13/02/2022. Rate: $3000
Room: Dhofar. Available on 11/11/2021. Rate: $2500
Room: Nizwa. Available on 13/12/2022. Rate: $1200
Please let me know which ones you are interested so we go through more details.
Best regards,
Salim Al Amri"""
print(re.findall(r'[:;]\s*(.+?)\s*<', s))
['Al Amri, Salim', 'Al Harthi, Mohammed', 'Al hajri, Malik', 'Omar, Naif']
-----------------------
[:;]\s*(.+?)\s*<
import re
s = """From: Al Amri, Salim <salim.amri@gmail.com>
Sent: 25 August 2021 17:20
To: Al Harthi, Mohammed <mohd4.king@rihal.om>
Ce: Al hajri, Malik <hajri990@ocaa.co.om>; Omar, Naif <nnnn49@apple.com>
Subject: Conference Rooms Booking Details
Dear Mohammed,
As per our last discussion these are the available conference rooms available for booking along
with their rates for full day:
Room: Luban, available on 26/09/2021. Rate: $4540
Room: Mazoon, available on 04/12/2021 and 13/02/2022. Rate: $3000
Room: Dhofar. Available on 11/11/2021. Rate: $2500
Room: Nizwa. Available on 13/12/2022. Rate: $1200
Please let me know which ones you are interested so we go through more details.
Best regards,
Salim Al Amri"""
print(re.findall(r'[:;]\s*(.+?)\s*<', s))
['Al Amri, Salim', 'Al Harthi, Mohammed', 'Al hajri, Malik', 'Omar, Naif']
-----------------------
OCR = """From: Al Amri, Salim <salim.amri@gmail.com>
Sent: 25 August 2021 17:20
To: Al Harthi, Mohammed <mohd4.king@rihal.om>
Ce: Al hajri, Malik <hajri990@ocaa.co.om>; Omar, Naif <nnnn49@apple.com>
Subject: Conference Rooms Booking Details
Dear Mohammed,
As per our last discussion these are the available conference rooms available for booking along
with their rates for full day:
Room: Luban, available on 26/09/2021. Rate: $4540
Room: Mazoon, available on 04/12/2021 and 13/02/2022. Rate: $3000
Room: Dhofar. Available on 11/11/2021. Rate: $2500
Room: Nizwa. Available on 13/12/2022. Rate: $1200
Please let me know which ones you are interested so we go through more details.
Best regards,
Salim Al Amri"""
names = []
for line in OCR.split('\n'):
tokens = line.split()
if tokens and tokens[0] in ['From:', 'To:', 'Ce:']: # Ce or Cc ???
parts = line.split(';')
for i, p in enumerate(parts):
names.append(' '.join(p.split()[i==0:-1]))
print(names)
QUESTION
How to extract a human name in a string python
Asked 2022-Jan-07 at 14:44I have a string out of an OCR'ed image, and I need to find a way to extract human names from it. here is the image required to OCR, which comes out as:
From: Al Amri, Salim <salim.amri@gmail.com>
Sent: 25 August 2021 17:20
To: Al Harthi, Mohammed <mohd4.king@rihal.om>
Ce: Al hajri, Malik <hajri990@ocaa.co.om>; Omar, Naif <nnnn49@apple.com>
Subject: Conference Rooms Booking Details
Dear Mohammed,
As per our last discussion these are the available conference rooms available for booking along
with their rates for full day:
Room: Luban, available on 26/09/2021. Rate: $4540
Room: Mazoon, available on 04/12/2021 and 13/02/2022. Rate: $3000
Room: Dhofar. Available on 11/11/2021. Rate: $2500
Room: Nizwa. Available on 13/12/2022. Rate: $1200
Please let me know which ones you are interested so we go through more details.
Best regards,
Salim Al Amri
There are 4 names in total in the heading, and i am required to get the output:
names = 'Al Hajri, Malik', 'Omar, Naif', 'Al Amri, Salim', 'Al Harthy, Mohammed' #desired output
but I have no idea how to extract the names. I have tried RegEx and came up with:
names = re.findall(r'(?i)([A-Z][a-z]+[A-Z][a-z][, ] [A-Z][a-z]+)', string) #regex to find names
which searches for a Capital letter, then a comma, then another word starting with a capital letter. it is close to the desired result but it comes out as:
names = ['Amri, Salim', 'Harthi, Mohammed', 'hajri, Malik', 'Omar, Naif', 'Luban, available', 'Mazoon, available'] #acutal result
I have thought of maybe using another string that extracts the room names and excludes them from the list, but i have no idea how to implement that idea. i am new to RegEx, so any help will be appreciated. thanks in advance
ANSWER
Answered 2022-Jan-07 at 14:41Depending on the contents of your email, a reasonable approach might be to use:
[:;]\s*(.+?)\s*<
See an online demo.
[:;]
- A (semi-)colon;\s*
- 0+ (Greedy) whitespaces;(.+?)
- A 1st capture group of 1+ (Lazy) characters;\s*
- 0+ (Greedy) whitespaces;<
- A literal '<'.Note that I specifically use (.+?)
to capture names since names are notoriously hard to match.
import re
s = """From: Al Amri, Salim <salim.amri@gmail.com>
Sent: 25 August 2021 17:20
To: Al Harthi, Mohammed <mohd4.king@rihal.om>
Ce: Al hajri, Malik <hajri990@ocaa.co.om>; Omar, Naif <nnnn49@apple.com>
Subject: Conference Rooms Booking Details
Dear Mohammed,
As per our last discussion these are the available conference rooms available for booking along
with their rates for full day:
Room: Luban, available on 26/09/2021. Rate: $4540
Room: Mazoon, available on 04/12/2021 and 13/02/2022. Rate: $3000
Room: Dhofar. Available on 11/11/2021. Rate: $2500
Room: Nizwa. Available on 13/12/2022. Rate: $1200
Please let me know which ones you are interested so we go through more details.
Best regards,
Salim Al Amri"""
print(re.findall(r'[:;]\s*(.+?)\s*<', s))
Prints:
['Al Amri, Salim', 'Al Harthi, Mohammed', 'Al hajri, Malik', 'Omar, Naif']
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit