Giter VIP home page Giter VIP logo

hatebase's Introduction

archive notice
Although Hatebase remains an active project, it's transitioned from a back-end service to a front-end service, and thus no longer offers an API.

=====================================================

hatebase

Python Version of Andrew Welter's Hatebase Wrapper Using the current 4.2 Version of the Hatebase API

Install

pip install hatebase

Requirements

pip install requests

HatebaseAPI functions

Initialize HatebaseAPI class

from hatebase import HatebaseAPI
key = 'yourHatebaseAPIKeyString'
hatebase = HatebaseAPI({"key": key})
# for more details, set debug to True
hatebase = HatebaseAPI({"key": key, "debug": True})

HatebaseAPI getVocabulary

# set filters for vocabulary query
filters = {"language": "eng"}
format = "json"

response = hatebase.getVocabulary(filters=filters, format=format)

# get some details from response
vocablist = response["result"]
results = response["number_of_results"]
pages = response["number_of_pages"]

HatebaseAPI getVocabularyDetails

format = "json"
details_filters = {'vocabulary_id': vocab_id}

response = hatebase.getVocabularyDetails(filters=details_filters, format=format)

HatebaseAPI getSightings

filters = {'is_about_nationality': '1', 'language': 'eng', 'country_id': 'US'}
format = "json"

response = hatebase.getSightings(filters=filters, format=format)

HatebaseAPI analyze

# TBD

HatebaseAPI getAnalysis

# TBD

Examples

Get All the Hate Speech in English About Nationality in the US

import json
import requests
from hatebase import HatebaseAPI

hatebase = HatebaseAPI({"key": key})
filters = {'is_about_nationality': '1', 'language': 'eng', 'country_id': 'US'}
format = "json"
json_response = hatebase.getSightings(filters=filters, format=format)

Get All Arabic Vocabulary

from json 
import requests
import pandas as pd
from hatebase import HatebaseAPI

hatebase = HatebaseAPI({"key": key})
filters = {"language": "ara"}
format = "json"
# initialize list for all vocabulary entry dictionaries
ara_vocab = []
response = hatebase.getVocabulary(filters=filters, format=format)
pages = response["number_of_pages"]
# fill the vocabulary list with all entries of all pages
# this might take some time...
for page in range(1, pages+1):
    filters["page"] = str(page) 
    response = hatebase.getVocabulary(filters=filters, format=format)
    ara_vocab.append(response["result"])

# create empty pandas df for all vocabulary entries
df_ara_vocab = pd.DataFrame()
# fill df
for elem in ara_vocab:
    df_ara_vocab = df_ara_vocab.append(elem)
# reset the df index
df_ara_vocab.reset_index(drop=True, inplace=True)    

For more documentation on the API check out https://github.com/hatebase/Hatebase-API-Docs

Testing

To test the package run

python -m unittest hatebase.tests.test

hatebase's People

Contributors

danieljdufour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hatebase's Issues

How can I get all English vocabularies in Hatebase?

from hatebase import HatebaseAPI
key = '~'
hatebase = HatebaseAPI({"key": key})
hatebase = HatebaseAPI({"key": key, "debug": True})
filters = {"language": "eng"}
format = "json"

response = hatebase.getVocabulary(filters=filters, format=format)

vocablist = response["result"]
results = response["number_of_results"]
pages = response["number_of_pages"]

If I run the code above, I get vocablist with length 100, results with length 1522, and pages as length 16.
I thought I would get the whole vocabulary of English HateBase words by this query but there were only 100 vocabularies returned.
Is there any way I could get the whole vocabulary?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.