Skip to content

Commit

Permalink
Add rule names for chunking and census examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alldefector committed Jul 31, 2016
1 parent d12c0ce commit dd80362
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/census/app.ddlog
Expand Up @@ -32,50 +32,63 @@ rich(id) = if income_bracket = ">50K" then TRUE else FALSE end

############# CATEGORICAL ###############

@name("workclass")
@weight(workclass)
rich(id) :- adult(id, _, workclass, _, _, _, _, _, _, _, _, _, _, _, _, income_bracket).

@name("education")
@weight(education)
rich(id) :- adult(id, _, _, _, education, _, _, _, _, _, _, _, _, _, _, income_bracket).

@name("marital_status")
@weight(marital_status)
rich(id) :- adult(id, _, _, _, _, _, marital_status, _, _, _, _, _, _, _, _, income_bracket).

@name("occupation")
@weight(occupation)
rich(id) :- adult(id, _, _, _, _, _, _, occupation, _, _, _, _, _, _, _, income_bracket).

@name("relationship")
@weight(relationship)
rich(id) :- adult(id, _, _, _, _, _, _, _, relationship, _, _, _, _, _, _, income_bracket).

@name("race")
@weight(race)
rich(id) :- adult(id, _, _, _, _, _, _, _, _, race, _, _, _, _, _, income_bracket).

@name("gender")
@weight(gender)
rich(id) :- adult(id, _, _, _, _, _, _, _, _, _, gender, _, _, _, _, income_bracket).

@name("native_country")
@weight(native_country)
rich(id) :- adult(id, _, _, _, _, _, _, _, _, _, _, _, _, _, native_country, income_bracket).



############# CONTINUOUS ###############

@name("age")
@weight("")
@feature_value(age)
rich(id) :- adult(id, age, _, _, _, _, _, _, _, _, _, _, _, _, _, income_bracket).

@name("education_num")
@weight("")
@feature_value(education_num)
rich(id) :- adult(id, _, _, _, _, education_num, _, _, _, _, _, _, _, _, _, income_bracket).

@name("capital_gain")
@weight("")
@feature_value(capital_gain)
rich(id) :- adult(id, _, _, _, _, _, _, _, _, _, _, capital_gain, _, _, _, income_bracket).

@name("capital_loss")
@weight("")
@feature_value(capital_loss)
rich(id) :- adult(id, _, _, _, _, _, _, _, _, _, _, _, capital_loss, _, _, income_bracket).

@name("hours_per_week")
@weight("")
@feature_value(hours_per_week)
rich(id) :- adult(id, _, _, _, _, _, _, _, _, _, _, _, _, hours_per_week, _, income_bracket).
Expand All @@ -84,6 +97,7 @@ rich(id) :- adult(id, _, _, _, _, _, _, _, _, _, _, _, _, hours_per_week, _, inc

############# BUCKETIZED ###############

@name("age_bucket")
@weight(width_bucket(age, 18, 88, 10))
rich(id) :- adult(id, age, _, _, _, _, _, _, _, _, _, _, _, _, _, income_bracket).

Expand All @@ -92,9 +106,11 @@ rich(id) :- adult(id, age, _, _, _, _, _, _, _, _, _, _, _, _, _, income_bracket
############# COMPOSITE ###############


@name("education X occupation")
@weight(education, occupation)
rich(id) :- adult(id, _, _, _, education, _, occupation, _, _, _, _, _, _, _, _, income_bracket).


@name("race X occupation X age_bucket")
@weight(race, occupation, width_bucket(age, 18, 88, 10))
rich(id) :- adult(id, age, _, _, _, _, _, occupation, _, race, _, _, _, _, _, income_bracket).
7 changes: 7 additions & 0 deletions examples/chunking/app.ddlog
Expand Up @@ -38,20 +38,24 @@ chunk(s, word, tag) = (

# unigram features ###############################################################

@name("current word")
@weight(tag, word)
chunk(s, w, tag) :-
words(s, w, word, pos, _).

@name("current pos tag")
@weight(tag, pos)
chunk(s, w, tag) :-
words(s, w, word, pos, _).

@name("current and next pos")
@weight(tag, pos1, pos2)
chunk(s, w1, tag) :-
w2 = w1 + 1,
words(s, w1, word1, pos1, _),
words(s, w2, word2, pos2, _).

@name("current and prev pos")
@weight(tag, pos1, pos2)
chunk(s, w2, tag) :-
w2 = w1 + 1,
Expand All @@ -61,9 +65,11 @@ chunk(s, w2, tag) :-

# bigram features ###############################################################

@name("linear chain")
@weight(tag1, tag2)
chunk(s, w1, tag1) ^ chunk(s, w2, tag2) :- w2 = w1 + 1.

@name("linear chain by pos")
@weight(tag1, tag2, pos1, pos2)
chunk(s, w1, tag1) ^ chunk(s, w2, tag2) :-
w2 = w1 + 1,
Expand All @@ -73,6 +79,7 @@ chunk(s, w1, tag1) ^ chunk(s, w2, tag2) :-

# word embedding features ###############################################################

@name("word embedding")
@weight(tag, k)
@feature_value(vec[k])
chunk(s, w, tag) :-
Expand Down

0 comments on commit dd80362

Please sign in to comment.