Skip to content
antilectual edited this page Nov 5, 2018 · 1 revision
<style> </style>

Flask Installation:

  1. Installing Python 3
    1. https://www.python.org/downloads/
  2. Install Python virtual environment
    1. Pip install virtualenv
  3. Install Flask
    1. Pip install flask
    2. Flask service website/documentation and tutorials:
      1. http://flask.pocoo.org/docs/1.0/quickstart
  4. Install RDFLib
    1. Pip install rdflib
  5. Entering your VE
    1. cd “C:\Program Files (x86)\Pythong37-32\NRDC\Scripts”
      1. Location of environment
    2. .\activate
    3. cd “C:\inDev\NRDC\FlaskService\NRDCFlask
      1. Location of flask service

 

Creating a Flask service:

  1. Import flask
    1. from flask import Flask
      1. Import flask
    2. <flask_service_name> = Flask(_name_)
      1. Define an application to build, which will be referred to as this name
    3. from app import <filename/flask_service_name>
      1. This is important for splitting code over multiple files (best guess, no documentation)
      2. Put this at the bottom of the file used to initialize flask to avoid circular imports
  2. Creating a route/page
    1. @<flask_service_name>.route(‘/<URI path>’)
      1. Create a web path to access a new web page
      2. These cascade until reaching a define function so stacking two paths with only one define creates the same behavior on both pages
    2. Define function
      1. def <function_name>():
        1. Starts a new function
        2. Must end in a return or the interpreter throws errors
    3. Important notes on return
      1. If returning the tuples list, remember to jsonify() it on return
        1. This formats the list into an object that is json compatible
        2. Otherwise, the page will load with internal server errors

 

Writing the function:

  1. Define function (see 2.b)
  2. Indents are important. Whitespace matters in Python
  3. Variables are loosely defined (data types are not necessary when defining a variable)
    1. Ex: g = 1 is a valid declaration
  4. For loops
    1. For loops in python do not use iterators like in c/c++/c# i.e. for(i = 0; i < j ; i++)
      1. For loops use a variable within a variable
        1. For g in s (g is a variable defined in the for loop. Assume s is a list of strings. Then g is each string in the list)
    2. For loops depend on indents to determine where they end since there are no ‘{}’ to define start and stop to functions, loops, conditionals
  5. If/Else/If else
    1. If statements are defined by if <condition> :
    2. If statements rely on indents to determine the end of the conditional statement
    3. If else is defined as elif <condition> :
    4. Else statements are defined as else :

 

Running your flask service

  1. set FLASK_APP=<filename>
  2. python -m flask run

 

Reading output

  1. An example: Finding your organizational tiers
  2. S, O, P and you
    1. S: subject
    2. O: object
    3. P: predicte
    4. The sky is blue
      1. S: sky, O: blue, P: is
    5. This can be used to find your organizational tiers
      1. Ex: Site-Network is a type of organizational tier
        1. Site is a child of Site-network
        2. <Unique ID> is a characteristic of a site
        3. <Unique ID> has label Alias
      2. The sites/Site-Network/Characteristics are then found and filled using the database

 

 

Ideas for breaking up Ontology for specific information:

  1. S:
    1. Always URI or unique identifier
    2.  
  2. P:
  3. O:

Clone this wiki locally