Hi All,
I'm close to buttoning up a stored procedure that parses out words in a sentence into a word array. I'm using a SQL statement to see if each word in that sentence is kosher. If there are any profanities, then I would like to catch it and print the list of those words onto the GUI.
Well, I do have one problem. If a swear word is used twice and not separated by a space between the two words, then it makes it through the filter. This is not what I want and could create some problems down the road. I would like to create a filter that will test for this kind of problem and retrieve the correct word or words based on the content. I'm thinking that I have to update this select statement or write som if blocks around it.
Any ideas?
Todd
I'm close to buttoning up a stored procedure that parses out words in a sentence into a word array. I'm using a SQL statement to see if each word in that sentence is kosher. If there are any profanities, then I would like to catch it and print the list of those words onto the GUI.
Code:
PROCEDURE RestrictedContent(InMessage IN VARCHAR2,
pList OUT VARCHAR2,
ErrorMsg OUT VARCHAR2,
ErrorCode OUT NUMBER)
AS
warray WORD_ARRAY;
word VARCHAR2(100) := '';
rword VARCHAR2(100) := '';
BEGIN
-- Initialize ErrorCode and ErrorMsg
ErrorCode := 0;
ErrorMsg := 'Success';
IF InMessage IS NULL THEN
RETURN;
END IF;
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: InMessage: ' || InMessage);
-- Call ArrayFromContent to create word array
ArrayFromContent(InMessage, warray);
-- Print out warray to debug
FOR i in 1..warray.COUNT LOOP
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: windex: ' || i);
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: warray: ' || warray(i));
END LOOP;
pList := '';
-- Compare each word to RESTRICTED_WORDS table
FOR i in 1..warray.COUNT LOOP
word := warray(i);
BEGIN
SELECT RESTRICTED_WORD INTO rword
FROM RESTRICTED_WORDS
WHERE LOWER(RESTRICTED_WORD) LIKE LOWER('%'||word||'%');
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: Match: ' || rword || ' ' || warray(i));
-- Build comma-delimited list, plist, of profanity words...
IF LENGTH(rword) > 0 THEN
IF LENGTH(pList) > 0 THEN
pList := CONCAT(pList, ', ');
END IF;
pList := CONCAT(pList, rword);
END IF;
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: pList: ' || pList);
EXCEPTION
WHEN OTHERS
THEN
ErrorMsg := 'Select Restricted Words, Did not find a match!';
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: Error: ' || ErrorMsg);
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
UTILITIES_PKG.fprintf('debug.txt', 'RestrictedContent: Error: ' || ErrorMsg);
ErrorMsg := 'Restricted Words failed!';
ErrorCode := -20000;
--RAISE_APPLICATION_ERROR(-20000, 'Restricted Words timeout!');
END RestrictedContent;
PROCEDURE ArrayFromContent(InMessage IN VARCHAR2,
warray IN OUT WORD_ARRAY)
AS
word VARCHAR2(100);
pos NUMBER;
windex NUMBER;
Content VARCHAR2(512);
BEGIN
windex := 0;
-- Remove all leading and trailing spaces
--Content := LTRIM(RTRIM(InMessage));
Content := TRIM(BOTH ' ' FROM InMessage);
-- Use TRANSLATE to replace numbers and some punctuation with empty spaces
Content := TRANSLATE(Content,'0123456789-?!/\,;:(){}"',' ');
-- Use REPLACE to replace remaining punctuation with empty spaces
Content := REPLACE(Content, CHR(10), ' '); --linefeed character
Content := REPLACE(Content, CHR(13), ' '); --carriage return character
Content := REPLACE(Content, '@', ' ');
Content := REPLACE(Content, '.', ' ');
Content := REPLACE(Content, 'http', ' ');
Content := REPLACE(Content, '[URL unfurl="true"]www',[/URL] ' ');
UTILITIES_PKG.fprintf('debug.txt', 'ArrayFromContent: Content: ' || Content);
pos := INSTR(Content, ' ');
-- Build array of words from message content...
WHILE pos > 0 LOOP
-- Fetch first word from Content...
-- Trim off any trailing spaces from word
word := RTRIM(SUBSTR(Content, 1, pos-1));
--UTILITIES_PKG.fprintf('debug.txt', 'ArrayFromContent: word:' || word || ':');
windex := windex + 1;
IF LENGTH(word) > 0 THEN
warray(windex) := word;
END IF;
-- Trim off any leading spaces from remaining content
-- this is precautionary
Content := LTRIM(SUBSTR(Content, pos + 1, LENGTH(Content) - pos + 1));
--UTILITIES_PKG.fprintf('debug.txt', 'ArrayFromContent: Content: ' || Content);
pos := INSTR(Content, ' ');
END LOOP;
-- Handle trailing word from Content...
IF LENGTH(Content) > 0 THEN
warray(windex + 1) := Content;
END IF;
END ArrayFromContent;
Well, I do have one problem. If a swear word is used twice and not separated by a space between the two words, then it makes it through the filter. This is not what I want and could create some problems down the road. I would like to create a filter that will test for this kind of problem and retrieve the correct word or words based on the content. I'm thinking that I have to update this select statement or write som if blocks around it.
Code:
SELECT RESTRICTED_WORD INTO rword
FROM RESTRICTED_WORDS
WHERE LOWER(RESTRICTED_WORD) LIKE LOWER('%'||word||'%');
Any ideas?
Todd