The BOOLRULE Procedure
Getting Started: BOOLRULE Procedure
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
The following DATA step creates a data table that contains 20 observations that have three variables. The Text variable contains the input documents. The apple_fruit variable contains the label of documents: a value of 1 indicates that the document is related to the apple as the fruit or to the apple tree. The DID variable contains the ID of the documents. Each row in the data table represents a document for analysis.
data mycas.getstart;
infile datalines delimiter='|' missover;
length text $150;
input text$ apple_fruit did$;
datalines;
Delicious and crunchy apple is one of the popular fruits | 1 |d01
Apple was the king of all fruits. | 1 |d02
Custard apple or Sitaphal is a sweet pulpy fruit | 1 |d03
apples are a common tree throughout the tropics | 1 |d04
apple is round in shape, and tasts sweet | 1 |d05
Tropical apple trees produce sweet apple| 1| d06
Fans of sweet apple adore Fuji because it is the sweetest of| 1 |d07
this apple tree is small | 1 |d08
Apple Store shop iPhone x and iPhone x Plus.| 0 |d09
See a list of Apple phone numbers around the world.| 0 |d10
Find links to user guides and contact Apple Support, | 0 |d11
Apple counters Samsung Galaxy launch with iPhone gallery | 0 |d12
Apple Smartphones - Verizon Wireless.| 0 |d13
Apple mercurial chief executive, was furious.| 0 |d14
Apple has upgraded the phone.| 0 |d15
the great features of the new Apple iPhone x.| 0 |d16
Apple sweet apple iphone.| 0 |d17
Apple apple will make cars | 0 |d18
Apple apple also makes watches| 0 |d19
Apple apple makes computers too| 0 |d20
;
run;
These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
The following statements use the TEXTMINE procedure to parse the input text data. The generated term-by-document matrix is stored in a data table named mycas.bow. The summary information about the terms in the document collection is stored in a data table named mycas.terms.
proc textmine data=mycas.getstart language="english";
doc_id
did;
var
text;
parse
nonoungroups
entities = none
outparent = mycas.bow
outterms = mycas.terms
reducef = 1;
run;
The following statements use the BOOLRULE procedure to extract rules:
proc boolrule
data = mycas.bow
docid = _document_
termid = _termnum_
docinfo = mycas.getstart
terminfo = mycas.terms
minsupports = 1
mpos = 1
gpos = 1;
docinfo
id = did
targets = (apple_fruit);
terminfo
id = key
label = term;
output
rules = mycas.rules
ruleterms = mycas.ruleterms;
run;
The mycas.bow and mycas.terms data sets are specified as input in the DATA= and TERMINFO= options, respectively, in the PROC BOOLRULE statement. In addition, the DOCID= and TERMID= options in the PROC BOOLRULE statement specify the columns of the mycas.bow data table that contain the document ID and term ID, respectively.
The DOCINFO statement specifies the following information about the mycas.GetStart data table:
The ID= option specifies the column that contains the document ID. The variables in this column are matched to the document ID variable that is specified in the DOCID= option in the PROC BOOLRULE statement in order to fetch target information about documents for rule extraction.
The TARGETS= option specifies the target variables.
The TERMINFO statement specifies the following information about the mycas.terms data table:
The ID= option specifies the column that contains the term ID. The variables in this column are matched to the term ID variable that is specified in the TERMID= option in the PROC BOOLRULE statement in order to fetch information about terms for rule extraction.
The LABEL= option specifies the column that contains the text of the terms.
The OUTPUT statement requests that the extracted rules be stored in the data table mycas.Rules.
Figure 1 shows the SAS log that PROC BOOLRULE generates; the log provides information about the default configurations used by the procedure, about where the procedure runs, and about the input and output files. The log shows that the mycas.rules data table contains two observations, indicating that the BOOLRULE procedure identified two rules for the apple_fruit category.
Figure 1: SAS Log
| NOTE: Neither SEQCOVER nor NOSEQCOVER is specified. SEQCOVER is used by default. |
| NOTE: The Cloud Analytic Services server processed the request in 0.068507 |
| seconds. |
| NOTE: The data set MYCAS.RULES has 2 observations and 15 variables. |
| NOTE: The data set MYCAS.RULETERMS has 3 observations and 9 variables. |
The following statements PROC PRINT to show the contents of the mycas.rules data table that the BOOLRULE procedure generates:
proc print data = mycas.rules;
var target ruleid rule F1 precision recall;
run;
Figure 2 shows the output of PROC PRINT, which contains two rules. For information about the output of the RULES= option, see the section RULES= Data Table.
Figure 2: The mycas.rules Data Table
| Obs | TARGET | RULEID | RULE | F1 | PRECISION | RECALL |
|---|---|---|---|---|---|---|
| 1 | apple_fruit | 1 | be & ~apple | 0.93333 | 1 | 0.875 |
| 2 | apple_fruit | 2 | produce | 1.00000 | 1 | 1.000 |
The following statements run the BOOLRULE procedure to match rules in documents and run PROC PRINT to show the results:
proc boolrule
data = mycas.bow
docid = _document_
termid = _termnum_;
score
ruleterms = mycas.ruleterms
outmatch = mycas.matches;
run;
proc print data=mycas.matches;
run;
Figure 3 shows the output of PROC PRINT, the mycas.matches data table. For information about the output of the OUTMATCH= option, see the section OUTMATCH= Data Table.
Figure 3: The mycas.matches Data Table
| Obs | _DOCUMENT_ | _TARGET_ | _RULE_ID_ |
|---|---|---|---|
| 1 | d01 | 1 | 1 |
| 2 | d06 | 1 | 2 |
| 3 | d09 | . | 0 |
| 4 | d11 | . | 0 |
| 5 | d16 | . | 0 |
| 6 | d17 | . | 0 |
| 7 | d04 | 1 | 1 |
| 8 | d07 | 1 | 1 |
| 9 | d14 | . | 0 |
| 10 | d15 | . | 0 |
| 11 | d19 | . | 0 |
| 12 | d02 | 1 | 1 |
| 13 | d03 | 1 | 1 |
| 14 | d05 | 1 | 1 |
| 15 | d08 | 1 | 1 |
| 16 | d10 | . | 0 |
| 17 | d12 | . | 0 |
| 18 | d13 | . | 0 |
| 19 | d18 | . | 0 |
| 20 | d20 | . | 0 |