Exemple #1
0
    def to_native(self, ruleset):
        from syntaxrules import SyntaxTree, get_struct_tokens
        if self.many is False:  # explicit compare because we don't want None
            # Get parse
            module = ruleset.preprocessing
            saf = get_result(self.context['article'], module)
            t = SyntaxTree(saf)

            if self.context['preprocess']:
                r = RuleSet.objects.get(pk=int(self.context['preprocess']))
                t.apply_ruleset(r.get_ruleset())

            # Apply rules
            t.apply_ruleset(ruleset.get_ruleset())
            return list(get_struct_tokens(t.get_structs()))

        res = super(RulesetSerializer, self).to_native(ruleset)
        return res
Exemple #2
0
    def to_native(self, ruleset):
        from syntaxrules import SyntaxTree, get_struct_tokens
        if self.many is False: # explicit compare because we don't want None
            # Get parse
            module = ruleset.preprocessing
            saf = get_result(self.context['article'], module)
            t = SyntaxTree(saf)

            if self.context['preprocess']:
                r = RuleSet.objects.get(pk=int(self.context['preprocess']))
                t.apply_ruleset(r.get_ruleset())

            # Apply rules
            t.apply_ruleset(ruleset.get_ruleset())
            return list(get_struct_tokens(t.get_structs()))

        res = super(RulesetSerializer,self).to_native(ruleset)
        return res
Exemple #3
0
from syntaxrules import SyntaxTree
import requests
import json

# create SyntaxTree object based on sentences from the unitt tests
saf_url = "https://raw.github.com/vanatteveldt/syntaxrules/master/tests/test_saf.json"
saf = open("/home/wva/syntaxrules/tests/test_saf.json")
#saf = requests.get(saf_url).json()
t = SyntaxTree(saf, sentence_id=1)

# Visualize to /tmp/test.png
#t.get_graphviz().draw("/tmp/test.png", prog="dot")

# apply rules
ruleset_url = "https://raw.github.com/vanatteveldt/syntaxrules/master/tests/test_rules.json"
#ruleset = requests.get(ruleset_url).json()
ruleset = json.load(open("/home/wva/syntaxrules/tests/test_rules.json"))
t.apply_ruleset(ruleset)
t.get_graphviz().draw("/tmp/test.png", prog="dot")
import sys; sys.exit()


# get newly created triples
triples = t.get_triples(ignore_grammatical=True)
print(triples[0].predicate)
print(triples[0].subject)

# get newly created triples in minimal json form
print t.get_triples(ignore_grammatical=True, minimal=True)

# Visualize to /tmp/test2.png, grey out syntax relations
Exemple #4
0
# create SyntaxTree object
from syntaxrules import SyntaxTree

t = SyntaxTree("http://localhost:3030/x")

# Load sentence from the unit tests
import requests

saf_url = "https://raw.github.com/anonymous-1/syntaxrules/master/tests/test_saf.json"
saf = requests.get(saf_url).json()
t.load_saf(saf, sentence_id=1)
# Visualize to /tmp/test.png
t.get_graphviz().draw("/tmp/test.png", prog="dot")

# apply rules
ruleset_url = "https://raw.github.com/anonymous-1/syntaxrules/master/tests/test_rules.json"
ruleset = requests.get(ruleset_url).json()
t.apply_ruleset(ruleset)

# get newly created triples
triples = t.get_triples(ignore_grammatical=True)
print(triples[0].predicate)
print(triples[0].subject)

# get newly created triples in minimal json form
print t.get_triples(ignore_grammatical=True, minimal=True)

# Visualize to /tmp/test2.png, grey out syntax relations
from syntaxrules import VIS_GREY_REL

g = t.get_graphviz(triple_args_function=VIS_GREY_REL)