<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2016, <NAME> <<EMAIL>>
#
# Permission to use, copy, modify, and/or distribute this software for any purpose
# with or without fee is hereby granted, provided that the above copyright notice
# and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.

__author__ = 'essepuntato'
import web
import json
from src.wl import WebLogger
from src.rrh import RewriteRuleHandler
from src.ldd import LinkedDataDirector
import requests
import urlparse
import re
from src.oh import OntologyHandler
import csv
from datetime import datetime

#new scripts
from src.sparql_endpoint import SparqlEndPoint

# Load the configuration file
with open("conf.json") as f:
    c = json.load(f)

pages = ["/", "about", "corpus", "model", "download", "sparql", "search", "publications", "licenses", "contacts"]

urls = (
    "(/)", "Home",
    "/(about)", "About",
    "/(model)", "Model",
    "/(corpus)", "CorpusIntro",
    "/corpus/(.+)", "Corpus",
    "/corpus/", "Corpus",
    "/(download)", "Download",
    "/(sparql)", "Sparql",
    "/(search)", "Search",
    "/browser/(.+)", "Browser",
    "/(publications)", "Publications",
    "/(licenses)", "Licenses",
    "/(contacts)", "Contacts",
    "/ontology(.+)?", "Ontology",
    "(/paper/.+)", "RawGit"
)

render = web.template.render(c["html"])

rewrite = RewriteRuleHandler(
    "Redirect",
    [
        ("^/corpus/context.json$",
         "http://rawgit.com/essepuntato/opencitations/master/corpus/context.json",
         True)
    ],
    urls
)

# Set the web logger
web_logger = WebLogger("opencitations.net", "opencitations_log.txt", [
    "REMOTE_ADDR",      # The IP address of the visitor
    "HTTP_USER_AGENT",  # The browser type of the visitor
    "HTTP_REFERER",     # The URL of the page that called your program
    "HTTP_HOST",        # The hostname of the page being attempted
    "REQUEST_URI"       # The interpreted pathname of the requested document
                        # or CGI (relative to the document root)
    ],
    {"REMOTE_ADDR": ["192.168.127.12", "127.0.0.1"]}  # uncomment this for real app
)

# Load the sparql configuration file
#with open("sparql-conf.json") as f:
#    s = json.load(f)

# Set the SPARQL endpoint
#sparql_ep = SparqlEndPoint(c["sparql_endpoint"],s["prefixes"])

class RawGit:
    def GET(self, u):
        web_logger.mes()
        raise web.seeother("http://rawgit.com/essepuntato/opencitations/master" + u)


class Redirect:
    def GET(self, u):
        web_logger.mes()
        raise web.seeother(rewrite.rewrite(u))


class WorkInProgress:
    def GET(self, active):
        web_logger.mes()
        return render.wip(pages, active)


class Home:
    def GET(self, active):
        web_logger.mes()
        cur_date = ""
        cur_tot = ""
        cur_cit = ""

        with open(c["statistics"]) as f:
            lastrow = None
            for lastrow in csv.reader(f): pass
            cur_date = datetime.strptime(
                lastrow[0], "%Y-%m-%dT%H:%M:%S").strftime("%B %d, %Y")
            cur_tot = lastrow[5]
            cur_cit = lastrow[2]
            cur_cited = lastrow[6]

        return render.home(pages, active, cur_date, cur_tot, cur_cit, cur_cited)


class About:
    def GET(self, active):
        web_logger.mes()
        return render.about(pages, active)


class CorpusIntro:
    def GET(self, active):
        web_logger.mes()
        return render.corpus(pages, active)


class Download:
    def GET(self, active):
        web_logger.mes()
        return render.download(pages, active)

class Browser:
    def GET(self, path):
        web.debug(path)
        data_path = "https://w3id.org/oc"+"/corpus/"+path
        web.debug(data_path)
        return render.browser(data_path)

class Search:
    def GET(self, active):
        web_logger.mes()
        query_string = web.ctx.env.get("QUERY_STRING")
        parsed_query = urlparse.parse_qs(query_string)<commit_msg>Fix oc.py for website<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2016, <NAME> <<EMAIL>>
#
# Permission to use, copy, modify, and/or distribute this software for any purpose
# with or without fee is hereby granted, provided that the above copyright notice
# and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.

__author__ = 'essepuntato'
import web
import json
from src.wl import WebLogger
from src.rrh import RewriteRuleHandler
from src.ldd import LinkedDataDirector
import requests
import urlparse
import re
from src.oh import OntologyHandler
import csv
from datetime import datetime

# Load the configuration file
with open("conf.json") as f:
    c = json.load(f)

pages = ["/", "about", "corpus", "model", "download", "sparql", "search", "publications", "licenses", "contacts"]

urls = (
    "(/)", "Home",
    "/(about)", "About",
    "/(model)", "Model",
    "/(corpus)", "CorpusIntro",
    "/corpus/(.+)", "Corpus",
    "/corpus/", "Corpus",
    "/(download)", "Download",
    "/(sparql)", "Sparql",
    "/(search)", "Search",
    "/(publications)", "Publications",
    "/(licenses)", "Licenses",
    "/(contacts)", "Contacts",
    "/ontology(.+)?", "Ontology",
    "(/paper/.+)", "RawGit"
)

render = web.template.render(c["html"])

rewrite = RewriteRuleHandler(
    "Redirect",
    [
        ("^/corpus/context.json$",
         "http://rawgit.com/essepuntato/opencitations/master/corpus/context.json",
         True)
    ],
    urls
)

# Set the web logger
web_logger = WebLogger("opencitations.net", "opencitations_log.txt", [
    "REMOTE_ADDR",      # The IP address of the visitor
    "HTTP_USER_AGENT",  # The browser type of the visitor
    "HTTP_REFERER",     # The URL of the page that called your program
    "HTTP_HOST",        # The hostname of the page being attempted
    "REQUEST_URI"       # The interpreted pathname of the requested document
                        # or CGI (relative to the document root)
    ],
    {"REMOTE_ADDR": ["192.168.127.12", "127.0.0.1"]}  # uncomment this for real app
)


class RawGit:
    def GET(self, u):
        web_logger.mes()
        raise web.seeother("http://rawgit.com/essepuntato/opencitations/master" + u)


class Redirect:
    def GET(self, u):
        web_logger.mes()
        raise web.seeother(rewrite.rewrite(u))


class WorkInProgress:
    def GET(self, active):
        web_logger.mes()
        return render.wip(pages, active)


class Home:
    def GET(self, active):
        web_logger.mes()
        cur_date = ""
        cur_tot = ""
        cur_cit = ""

        with open(c["statistics"]) as f:
            lastrow = None
            for lastrow in csv.reader(f): pass
            cur_date = datetime.strptime(
                lastrow[0], "%Y-%m-%dT%H:%M:%S").strftime("%B %d, %Y")
            cur_tot = lastrow[5]
            cur_cit = lastrow[2]
            cur_cited = lastrow[6]

        return render.home(pages, active, cur_date, cur_tot, cur_cit, cur_cited)


class About:
    def GET(self, active):
        web_logger.mes()
        return render.about(pages, active)


class CorpusIntro:
    def GET(self, active):
        web_logger.mes()
        return render.corpus(pages, active)


class Download:
    def GET(self, active):
        web_logger.mes()
        return render.download(pages, active)


class Search:
    def GET(self, active):
        web_logger.mes()
        query_string = web.ctx.env.get("QUERY_STRING")
        parsed_query = urlparse.parse_qs(query_string)
{'fraction_non_alphanumeric': 0.13089315328121298, 'fraction_numerical': 0.006278133143804786, 'mean_word_length': 2.9601313320825517, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2827187', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2633, 'n_words': 786}