From 939e7aa65abe18f57a129fee590f46b7cd32f688 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Fri, 5 Jun 2015 16:37:55 +0100 Subject: Violations processor (Python script). --- scripts/Violations_processor.py | 48 ++ scripts/list_of_words.txt | 907 +++++++++++++++++++++ .../LimitedSkolemisationApproximator.java | 4 +- 3 files changed, 957 insertions(+), 2 deletions(-) create mode 100644 scripts/Violations_processor.py create mode 100644 scripts/list_of_words.txt diff --git a/scripts/Violations_processor.py b/scripts/Violations_processor.py new file mode 100644 index 0000000..62c1ade --- /dev/null +++ b/scripts/Violations_processor.py @@ -0,0 +1,48 @@ +import json +import argparse +from os.path import dirname, join + +class Cleaner: + """Given a violation, it can make it very readable. + + For example from: + atLeast(1 )(X) :- (X) + to: + active(X) -> across(X,Y), act(Y) + """ + + def __init__(self): + with open(join(dirname(__file__),'list_of_words.txt'), 'r') as f: + self._words = [x.strip() for x in f] + self._used_words = 0 + self._cache = {} + + def clean(self, violation, prefix): + j = 0 + atoms = [] + for i in range(3): + i = violation.find('<', j) + 1 + j = violation.find('>', i) + atom = violation[i:j] + if atom not in self._cache: + self._cache[atom] = str(prefix) + self._words[self._used_words] + self._used_words += 1 + atoms.append(self._cache[atom]) + return '%10s(X) -> %10s(X,Y), %10s(Y)' % (atoms[2], atoms[0], atoms[1]) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Transform violations (as output by PAGOdA) into a very readable form.') + parser.add_argument('input', help='json file containing violations') + args = parser.parse_args() + + cleaner = Cleaner() + with open(args.input, 'r') as f: + violations_list_list = json.load(f)['violationClauses'] + clean_rules_list_list = [] + i = 0 + for violations_list in violations_list_list: + clean_rules_list_list.append(sorted(map(lambda x: cleaner.clean(x, i), violations_list))) + i += 1 + print json.dumps(clean_rules_list_list, indent=2) + diff --git a/scripts/list_of_words.txt b/scripts/list_of_words.txt new file mode 100644 index 0000000..5ac8658 --- /dev/null +++ b/scripts/list_of_words.txt @@ -0,0 +1,907 @@ +across +act +active +activity +add +afraid +age +ago +agree +air +alone +along +already +always +amount +angry +another +answer +anyone +anything +anytime +appear +apple +area +arm +army +around +arrive +art +ask +attack +aunt +autumn +away +baby +back +bad +bag +ball +bank +base +basket +bath +bean +bear +beautiful +bed +bedroom +beer +behave +begin +behind +bell +besides +best +better +big +bird +birth +birthday +bit +bite +black +bleed +block +blood +blow +blue +board +boat +body +boil +bone +book +border +born +borrow +bottle +bottom +bowl +box +boy +branch +brave +bread +break +breakfast +breathe +bridge +bright +bring +brother +brown +brush +build +burn +business +bus +busy +buy +cake +call +can +candle +cap +car +card +care +careful +careless +carry +case +cat +catch +central +century +certain +chair +chance +change +chase +cheap +cheese +chicken +child +children +chocolate +choice +choose +circle +city +class +clever +clean +clear +climb +clock +cloth +clothes +cloud +cloudy +close +coffee +coat +coin +cold +collect +colour +comb +comfortable +common +compare +come +complete +computer +condition +continue +control +cook +cool +copper +corn +corner +correct +cost +contain +count +country +course +cover +crash +cross +cry +cup +cupboard +cut +dance +dangerous +dark +daughter +day +dead +decide +decrease +deep +deer +depend +desk +destroy +develop +die +different +difficult +dinner +direction +dirty +discover +dish +dog +door +double +draw +dream +dress +drink +drive +drop +dry +duck +dust +duty +ear +early +earn +earth +east +easy +eat +education +effect +egg +eight +either +electric +elephant +else +empty +end +enemy +enjoy +enough +enter +equal +entrance +escape +even +evening +event +ever +every +everyone +exact +everybody +examination +example +except +excited +exercise +expect +expensive +explain +extremely +eye +face +fact +fail +fall +false +family +famous +far +farm +father +fast +fat +fault +fear +feed +feel +female +fever +fight +fill +film +find +fine +finger +finish +fire +first +fish +fit +five +fix +flag +flat +float +floor +flour +flower +fly +fold +food +fool +foot +football +force +foreign +forest +forget +forgive +fork +form +fox +four +free +freedom +freeze +fresh +friend +friendly +front +fruit +full +fun +funny +furniture +future +game +garden +gate +general +gentleman +get +gift +give +glad +glass +go +goat +god +gold +good +goodbye +grandfather +grandmother +grass +grave +great +green +grey +ground +group +grow +gun +hair +half +hall +hammer +hand +happen +happy +hard +hat +hate +head +healthy +hear +heavy +heart +heaven +height +hello +help +hen +hide +high +hill +hit +hobby +hold +hole +holiday +home +hope +horse +hospital +hot +hotel +house +hundred +hungry +hour +hurry +husband +hurt +I +ice +idea +important +increase +inside +introduce +invent +iron +invite +island +jelly +job +join +juice +jump +just +keep +key +kill +kind +king +kitchen +knee +knife +knock +know +ladder +lady +lamp +land +large +last +late +lately +laugh +lazy +lead +leaf +learn +leave +leg +left +lend +length +less +lesson +let +letter +library +lie +life +light +like +lion +lip +list +listen +little +live +lock +lonely +long +look +lose +lot +love +low +lower +luck +machine +main +make +male +man +many +map +mark +market +marry +matter +may +meal +mean +measure +meat +medicine +meet +member +mention +method +middle +milk +million +mind +minute +miss +mistake +mix +model +modern +moment +money +monkey +month +moon +morning +mother +mountain +mouth +move +much +music +must +name +narrow +nation +nature +near +nearly +neck +need +needle +neighbour +neither +net +never +new +news +newspaper +next +nice +night +nine +noble +noise +none +north +nose +nothing +notice +now +number +obey +object +ocean +offer +office +often +oil +old +one +open +opposite +orange +order +outside +page +pain +paint +pair +pan +paper +parent +park +part +partner +party +pass +past +path +pay +peace +pen +pencil +people +pepper +per +perfect +period +person +petrol +photograph +piano +pick +picture +piece +pig +pin +pink +place +plane +plant +plastic +plate +play +please +pleased +plenty +pocket +point +poison +police +polite +pool +poor +popular +position +possible +potato +pour +power +present +press +pretty +prevent +price +prince +prison +private +prize +probably +problem +produce +promise +proper +protect +provide +public +pull +punish +pupil +push +put +queen +question +quick +quiet +quite +radio +rain +rainy +raise +reach +read +ready +real +really +receive +record +red +remember +remind +remove +rent +repair +repeat +reply +report +rest +restaurant +result +return +rice +rich +ride +right +ring +rise +road +rob +rock +room +round +rubber +rude +rule +ruler +run +rush +sad +safe +sail +salt +sand +save +say +school +science +scissors +search +seat +second +see +seem +sell +send +sentence +serve +seven +several +sex +shade +shadow +shake +shape +share +sharp +sheep +sheet +shelf +shine +ship +shirt +shoe +shoot +shop +short +shoulder +shout +show +sick +side +signal +silence +silly +silver +similar +simple +single +since +sing +sink +sister +sit +six +size +skill +skin +skirt +sky +sleep +slip +slow +small +smell +smile +smoke +snow +soap +sock +soft +someone +something +sometimes +son +soon +sorry +sound +soup +south +space +speak +special +speed +spell +spend +spoon +sport +spread +spring +square +stamp +stand +star +start +station +stay +steal +steam +step +still +stomach +stone +stop +store +storm +story +strange +street +strong +structure +student +study +stupid +subject +substance +successful +sudden +sugar +suitable +summer +sun +sunny +support +sure +surprise +sweet +swim +sword +table +take +talk +tall +taste +taxi +tea +teach +team +tear +telephone +television +tell +ten +tennis +terrible +test +therefore +thick +thin +thing +think +third +though +threat +three +tidy +tie +title +today +toe +together +tomorrow +tonight +tool +tooth +top +total +touch +town +train +tram +travel +tree +trouble +true +trust +twice +try +turn +type +ugly +uncle +understand +unit +use +useful +usual +usually +vegetable +village +voice +visit +wait +wake +walk +want +warm +wash +waste +watch +water +way +weak +wear +weather +wedding +week +weight +welcome +well +west +wet +wheel +white +wide +wife +wild +will +win +wind +window +wine +winter +wire +wise +wish +without +woman +wonder +word +work +world +worry +yard +yell +yesterday +yet +young +zero +zoo diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java index da67264..dfe1e59 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java @@ -8,8 +8,8 @@ import uk.ac.ox.cs.pagoda.util.tuples.Tuple; import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** * Approximates existential rules through a limited form of Skolemisation. @@ -45,7 +45,7 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima case 1: return overApprox(clause, originalClause, violationTuples); case 0: - return Arrays.asList(clause); + return Collections.singletonList(clause); default: throw new IllegalArgumentException( "Expected clause with head length < 1, but it is " + clause.getHeadLength()); -- cgit v1.2.3