def __init__(self): print("Initializing INFERNO NLG Engine...") self.pp = pprint.PrettyPrinter(indent=4) self.realise = Realiser(host='nlg.kutlak.info', port=40000) self.ontology_base_url = "http://www.semanticweb.org/raneeshgomez/ontologies/2020/fyp-solar-system#" self.rdf_base_url = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" self.rdfs_base_url = "http://www.w3.org/2000/01/rdf-schema#" self.owl_base_url = "http://www.w3.org/2002/07/owl#" self.disregarded_types = ['DatatypeProperty', 'ObjectProperty', 'InverseObjectProperty', 'NamedIndividual', 'AnonymousIndividual', 'Class', 'TransitiveProperty', 'FunctionalProperty', 'InverseFunctionalProperty', 'SymmetricProperty', 'Restriction']
def translate(request): """Read a given FOL formula as jason data and return it as text. """ response_data = {} formula = request.POST['formula'].strip() response_data['formula'] = formula simplifications = [ x.strip() for x in request.POST.get('simplifications', '').split('|') ] try: realise = Realiser(host='roman.kutlak.info') if formula: template_instances = TemplateModel.objects.all() templates = {} errors = [] for t in template_instances: name = t.name try: template = eval(t.content) templates[name] = template except Exception as e: errors.append( ('danger', str(e))) # use bootstrap terminology... lex = Lexicaliser(templates=templates) response_data['text'] = realise(lex(formula_to_rst(expr(formula)))) response_data['status'] = 'success' response_data['messages'] = json.dumps(errors) else: response_data[ 'text'] = "Enter a formula first. E.g., 'happy(roman)'" response_data['status'] = 'default' except nltk.sem.logic.LogicalExpressionException as e: response_data['text'] = str(e) response_data['status'] = 'error' except Exception as e: logger.exception(e) return JsonResponse(response_data)
from nlglib.realisation.simplenlg.realisation import Realiser from nlglib.microplanning import * realise_en = Realiser(host='nlg.kutlak.info', port=40000) realise_es = Realiser(host='nlg.kutlak.info', port=40001) def main(): p = Clause(Mara, perseguir, un mono) p['TENSE'] = 'PAST' # expected = 'Mara persigue un mono' print(realise_es(p)) p = Clause(NP(la, rpida, corredora), VP(perseguir), NP(un, mono)) subject = NP(la, corredora) objekt = NP(un, mono) verb = VP(perseguir) subject.premodifiers.append(rpida) p.subject = subject p.predicate = verb p.object = objekt # expected = 'La rpida corredora persigue un mono.' print(realise_es(p)) p = Clause(NP('this', 'example'), VP('show', 'how cool simplenlg is')) # expected = This example shows how cool simplenlg is. print(realise_en(p)) if __name__ == '__main__': main()
#Build Text Model using Makovify text_model = markovify.NewlineText(input_text.headline_text, state_size = 2) #Generate Random Headlines # Print ten randomly-generated sentences using the built model for i in range(10): print(text_model.make_sentence()) #SimpleNLG #Load the library import logging from nlglib.realisation.simplenlg.realisation import Realiser from nlglib.microplanning import * realise = Realiser(host='nlg.kutlak.info') #Tense def tense(): c = Clause('Harry', 'bought', 'these off amazon') c['TENSE'] = 'PAST' print(realise(c)) c['TENSE'] = 'FUTURE' print(realise(c)) #Negation def negation(): c = Clause('Harry', 'bought', 'these off amazon') c['NEGATED'] = 'true' print(realise(c))
from nlglib.realisation.simplenlg.realisation import Realiser from nlglib.microplanning import * realise_en = Realiser(host='roman.kutlak.info', port=40000) p = Clause(NP('this', 'example'), VP('show', 'how cool simplenlg is')) print(realise_en(p))
def __init__(self): self.realise = Realiser(host='nlg.kutlak.info') self.ngram = n_gram(3, .06, logging=True) self.ngram.manual_interpolation([.6, .3, .1]) self.ngram.load_n_gram()
def run(): realise = Realiser(host='nlg.kutlak.info') lex = Lexicaliser( templates={ 'x': String('X'), 'arthur': Male('Arthur'), 'shrubbery': Clause(Var(0), VP('find', NP('a', 'shrubbery'), features=[TENSE.future])), 'knight': Clause(Var(0), VP('is', NP('a', 'knight'))), 'say_ni': Clause(Var(0), VP('say', Interjection('"Ni!"'))), }) print(realise(lex(formula_to_rst(expr(r'x'))))) print(realise(lex(formula_to_rst(expr(r'-x'))))) print(realise(lex(formula_to_rst(expr(r'x = 5'))))) print(realise(lex(formula_to_rst(expr(r'x != 5'))))) print(realise(lex(formula_to_rst(expr(r'knight(arthur)'))))) print(realise(lex(formula_to_rst(expr(r'-knight(arthur)'))))) print(realise(lex(formula_to_rst(expr(r'say_ni(arthur)'))))) print(realise(lex(formula_to_rst(expr(r'-say_ni(arthur)'))))) print(realise(lex(formula_to_rst(expr(r'shrubbery(arthur)'))))) print(realise(lex(formula_to_rst(expr(r'-shrubbery(arthur)'))))) print( realise(lex(formula_to_rst(expr(r'knight(arthur) & say_ni(arthur)'))))) print( realise(lex(formula_to_rst(expr(r'say_ni(arthur) | knight(arthur)'))))) print( realise(lex(formula_to_rst( expr(r'say_ni(arthur) -> knight(arthur)'))))) print( realise(lex(formula_to_rst( expr(r'knight(arthur) <-> say_ni(arthur)'))))) print( realise(lex(formula_to_rst( expr(r'say_ni(arthur) & -knight(arthur)'))))) print( realise(lex(formula_to_rst( expr(r'say_ni(arthur) | -knight(arthur)'))))) print( realise(lex(formula_to_rst( expr(r'say_ni(arthur) -> -knight(arthur)'))))) print( realise( lex(formula_to_rst(expr(r'-knight(arthur) <-> say_ni(arthur)'))))) print( realise( lex(formula_to_rst(expr(r'-knight(arthur) <-> -say_ni(arthur)'))))) print( realise( lex(formula_to_rst( expr(r'-(knight(arthur) <-> say_ni(arthur))'))))) print( realise( lex( formula_to_rst( expr(r'say_ni(arthur) & knight(arthur) & shrubbery(arthur)' ))))) print( realise( lex( formula_to_rst( expr(r'say_ni(arthur) | knight(arthur) | shrubbery(arthur)' )))))