-
Notifications
You must be signed in to change notification settings - Fork 1
Home
antilectual edited this page Nov 5, 2018
·
1 revision
<style>
</style>
Flask Installation:
- Installing Python 3
- Install Python virtual environment
- Pip install virtualenv
- Install Flask
- Pip install flask
- Flask service website/documentation and tutorials:
- Install RDFLib
- Pip install rdflib
- Entering your VE
- cd “C:\Program Files (x86)\Pythong37-32\NRDC\Scripts”
- Location of environment
- .\activate
- cd “C:\inDev\NRDC\FlaskService\NRDCFlask”
- Location of flask service
Creating a Flask service:
- Import flask
- from flask import Flask
- Import flask
- <flask_service_name> = Flask(_name_)
- Define an application to build, which will be referred to as this name
- from app import <filename/flask_service_name>
- This is important for splitting code over multiple files (best guess, no documentation)
- Put this at the bottom of the file used to initialize flask to avoid circular imports
- Creating a route/page
- @<flask_service_name>.route(‘/<URI path>’)
- Create a web path to access a new web page
- These cascade until reaching a define function so stacking two paths with only one define creates the same behavior on both pages
- Define function
- def <function_name>():
- Starts a new function
- Must end in a return or the interpreter throws errors
- Important notes on return
- If returning the tuples list, remember to jsonify() it on return
- This formats the list into an object that is json compatible
- Otherwise, the page will load with internal server errors
Writing the function:
- Define function (see 2.b)
- Indents are important. Whitespace matters in Python
- Variables are loosely defined (data types are not necessary when defining a variable)
- Ex: g = 1 is a valid declaration
- For loops
- For loops in python do not use iterators like in c/c++/c# i.e. for(i = 0; i < j ; i++)
- For loops use a variable within a variable
- 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)
- For loops depend on indents to determine where they end since there are no ‘{}’ to define start and stop to functions, loops, conditionals
- If/Else/If else
- If statements are defined by if <condition> :
- If statements rely on indents to determine the end of the conditional statement
- If else is defined as elif <condition> :
- Else statements are defined as else :
Running your flask service
- set FLASK_APP=<filename>
- python -m flask run
Reading output
- An example: Finding your organizational tiers
- S, O, P and you
- S: subject
- O: object
- P: predicte
- The sky is blue
- S: sky, O: blue, P: is
- This can be used to find your organizational tiers
- Ex: Site-Network is a type of organizational tier
- Site is a child of Site-network
- <Unique ID> is a characteristic of a site
- <Unique ID> has label Alias
- The sites/Site-Network/Characteristics are then found and filled using the database
Ideas for breaking up Ontology for specific information:
- S:
- Always URI or unique identifier
- P:
- O: