Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devmodified #236

Open
wants to merge 3 commits into
base: devmodified
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pattern/vector/svm/liblinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
if sys.platform == 'win32':
liblinear = CDLL(path.join(dirname, r'..\windows\liblinear.dll'))
else:
liblinear = CDLL(path.join(dirname, '../liblinear.so.3'))
liblinear = CDLL(path.join(dirname, 'macos/liblinear-2.20/liblinear.so.3'))
except:
# For unix the prefix 'lib' is not considered.
if find_library('linear'):
liblinear = CDLL(find_library('linear'))
elif find_library('liblinear'):
liblinear = CDLL(find_library('liblinear'))
else:
raise Exception('LIBLINEAR library not found.')
libsvm = CDLL(path.join(path.dirname(__file__), 'ubuntu/liblinear-2.20/liblinear.so.3'))

L2R_LR = 0
L2R_L2LOSS_SVC_DUAL = 1
Expand Down
6 changes: 4 additions & 2 deletions pattern/vector/svm/libsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
if sys.platform == 'win32':
libsvm = CDLL(path.join(dirname, r'..\windows\libsvm.dll'))
else:
libsvm = CDLL(path.join(dirname, '../libsvm.so.2'))
libsvm = CDLL(path.join(dirname, 'macos/libsvm-3.22/libsvm.so.2'))

except:
# For unix the prefix 'lib' is not considered.
if find_library('svm'):
libsvm = CDLL(find_library('svm'))
elif find_library('libsvm'):
libsvm = CDLL(find_library('libsvm'))
else:
raise Exception('LIBSVM library not found.')
libsvm = CDLL(path.join(path.dirname(__file__), 'ubuntu/libsvm-3.22/libsvm.so.2'))


C_SVC = 0
NU_SVC = 1
Expand Down
Binary file not shown.
Binary file added pattern/vector/svm/macos/libsvm-3.22/libsvm.so.2
Binary file not shown.
Binary file not shown.
Binary file added pattern/vector/svm/ubuntu/libsvm-3.22/libsvm.so.2
Binary file not shown.
20 changes: 16 additions & 4 deletions pattern/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,12 @@ def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=Non
- count: maximum 100.
There is a limit of 150+ queries per 15 minutes.
"""

def f(v):
v = v.get('extended_tweet', {}).get('full_text', v.get('full_text', v.get('text', '')))
return v


if type != SEARCH:
raise SearchEngineTypeError
if not query or count < 1 or (isinstance(start, (int, float)) and start < 1):
Expand All @@ -1748,6 +1754,7 @@ def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=Non
url.query = {
"q": query,
"max_id": id,
'tweet_mode': 'extended',
"count": min(count, 100)
}
# 2) Restrict location with geo=(latitude, longitude, radius).
Expand Down Expand Up @@ -1778,7 +1785,7 @@ def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=Non
r = Result(url=None)
r.id = self.format(x.get("id_str"))
r.url = self.format(TWITTER_STATUS % (x.get("user", {}).get("screen_name"), x.get("id_str")))
r.text = self.format(x.get("text"))
r.text = self.format(f(x))
r.date = self.format(x.get("created_at"))
r.author = self.format(x.get("user", {}).get("screen_name"))
r.language = self.format(x.get("metadata", {}).get("iso_language_code"))
Expand All @@ -1789,7 +1796,7 @@ def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=Non
if rt:
comment = re.search(r"^(.*? )RT", r.text)
comment = comment.group(1) if comment else ""
r.text = self.format("RT @%s: %s" % (rt["user"]["screen_name"], rt["text"]))
r.text = self.format("RT @%s: %s" % (rt["user"]["screen_name"], f(rt)))
results.append(r)
# Twitter.search(start=id, count=10) takes a tweet.id,
# and returns 10 results that are older than this id.
Expand Down Expand Up @@ -1879,15 +1886,20 @@ def __init__(self, socket, delimiter="\n", format=lambda s: s, **kwargs):
self.format = format

def parse(self, data):

""" TwitterStream.queue will populate with Result objects as
TwitterStream.update() is called iteratively.
"""
def f(v):
v = v.get('extended_tweet', {}).get('full_text', v.get('full_text', v.get('text', '')))
return v

if data.strip():
x = json.loads(data)
r = Result(url=None)
r.id = self.format(x.get("id_str"))
r.url = self.format(TWITTER_STATUS % (x.get("user", {}).get("screen_name"), x.get("id_str")))
r.text = self.format(x.get("text"))
r.text = self.format(f(x))
r.date = self.format(x.get("created_at"))
r.author = self.format(x.get("user", {}).get("screen_name"))
r.language = self.format(x.get("metadata", {}).get("iso_language_code"))
Expand All @@ -1898,7 +1910,7 @@ def parse(self, data):
if rt:
comment = re.search(r"^(.*? )RT", r.text)
comment = comment.group(1) if comment else ""
r.text = self.format("RT @%s: %s" % (rt["user"]["screen_name"], rt["text"]))
r.text = self.format("RT @%s: %s" % (rt["user"]["screen_name"], f(rt)))
return r


Expand Down