Author Topic: Check and filter profanity in a string with online API!  (Read 3574 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Check and filter profanity in a string with online API!
« on: July 20, 2020, 06:19:57 pm »
Here is some code I wrote up to use the Purgo Malum API to check for profanity and filter it out. You pass it a string with profanity (I've elected to not write it here in the source, so substitute with whatever stronger language you wish). Attached is a screenshot of the output:
 
profanity check.png

Code: QB64: [Select]
  1.  
  2. PRINT CheckProfanity("This is bullcrap, you know", "*")
  3.  
  4. FUNCTION CheckProfanity$ (text AS STRING, fillchar AS STRING)
  5.     DIM URL AS STRING
  6.     DIM URLFile AS STRING
  7.     DIM a%
  8.     DIM Request AS STRING
  9.     URLFile = "profanitycheck"
  10.     URL = "https://www.purgomalum.com/service/plain?text=" + FormatAsHTTP(text) + "&add=input&fill_char=" + fillchar
  11.     a% = API_Request(URL, URLFile)
  12.     DIM U AS INTEGER
  13.     U = FREEFILE
  14.     OPEN URLFile FOR BINARY AS #U
  15.     IF LOF(U) <> 0 THEN
  16.         LINE INPUT #U, Request
  17.     ELSE
  18.         CLOSE #U
  19.         KILL URLFile
  20.         CheckProfanity = ""
  21.         EXIT FUNCTION
  22.     END IF
  23.     CLOSE #U
  24.     KILL URLFile
  25.     CheckProfanity = Request
  26.  
  27. FUNCTION FormatAsHTTP$ (Request AS STRING)
  28.     start% = 1
  29.     DO
  30.         position% = INSTR(start%, Request, " ")
  31.         IF position% THEN
  32.             MID$(Request, position%, 1) = "+"
  33.             start% = position% + 1
  34.         END IF
  35.     LOOP UNTIL position% = 0
  36.     FormatAsHTTP = Request
  37.  
  38.     FUNCTION URLDownloadToFileA (BYVAL pCaller AS LONG, szURL AS STRING, szFileName AS STRING, BYVAL dwReserved AS LONG, BYVAL lpfnCB AS LONG)
  39.  
  40. FUNCTION API_Request (URL AS STRING, File AS STRING)
  41.     API_Request = URLDownloadToFileA(0, URL + CHR$(0), File + CHR$(0), 0, 0)
« Last Edit: July 20, 2020, 06:26:24 pm by SpriggsySpriggs »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Check and filter profanity in a string with online API!
« Reply #1 on: July 20, 2020, 06:46:05 pm »

EDIT: originally I had a comment about the incongruity between Spriggsy's code and code output snapshot. The output did not come from the code as shown. I had assumed it was and made comment about that, then I saw what he was doing and said "never mind" because I picked up what he was trying not to print. Then he explained that and now we pickup from there....


A+ for that!

All these API's you are posting, did you pick those up from your job?

Those seem like handy things for business.
« Last Edit: July 22, 2020, 02:38:55 pm by bplus »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Check and filter profanity in a string with online API!
« Reply #2 on: July 20, 2020, 07:01:48 pm »
A+ for that!

All these API's you are posting, did you pick those up from your job?

Those seem like handy things for business.
@bplus Actually, no. I just happened to discover that API strings work well in QB64 and started searching the internet for random APIs that I could use.
Shuwatch!