Commit e96a4fd2 authored by lambdamusic's avatar lambdamusic

fix bug discover models

parent bba82156
......@@ -261,7 +261,7 @@ v.preview() # => open in browser
- Github: [https://github.com/lambdamusic/ontospy](https://github.com/lambdamusic/ontospy)
- CheeseShop: [https://pypi.python.org/pypi/ontospy](https://pypi.python.org/pypi/ontospy)
- Homepage: [http://www.michelepasin.org/projects/ontospy](http://www.michelepasin.org/projects/ontospy)
- Docs: [http://lambdamusic.github.io/Ontospy/](http://lambdamusic.github.io/Ontospy/)
Also:
......
......@@ -11,6 +11,8 @@ Summary of changes.
- embedded ontodocs plugin within main source code
- requires install with [HTML] flag
- 'utils' and 'quickdocs' commands added to CLI
- CLI: all commands when called default to HELP
-
## November 12, 2018: v1.9.6
......
......@@ -47,10 +47,10 @@ SHELL_EXAMPLES = """
Quick Examples:
> ontospy ~/Desktop/mymodel.rdf # ==> inspect a local RDF file
> ontospy -l # ==> list ontologies available in the local library
> ontospy -s http://xmlns.com/foaf/spec/ # ==> download FOAF vocabulary and save it in library
> ontospy lib -s # ==> list ontologies available in the local library
> ontospy lib --save http://xmlns.com/foaf/spec/ # ==> download FOAF vocabulary and save it in library
More info: <ontospy.readthedocs.org>
More info: <http://lambdamusic.github.io/Ontospy/>
------------
"""
......@@ -113,7 +113,7 @@ Ontospy is a command line inspector for RDF/OWL models. Use the --help option wi
@click.option(
'--bootstrap',
is_flag=True,
help='BOOTSTRAP: bootstrap the local library with a few sample models.')
help='BOOTSTRAP: bootstrap the local library with popular ontologies.')
@click.option(
'--cache',
is_flag=True,
......@@ -140,14 +140,14 @@ Ontospy is a command line inspector for RDF/OWL models. Use the --help option wi
)
@click.argument('filepath', nargs=-1)
@click.pass_context
def library(ctx,
filepath=None,
bootstrap=False,
cache=False,
reveal=False,
show=False,
save=False,
directory=False):
def lib(ctx,
filepath=None,
bootstrap=False,
cache=False,
reveal=False,
show=False,
save=False,
directory=False):
"""
Work with a local library of RDF models. If no option or argument is passed, by default the library contents are listed.
"""
......@@ -156,14 +156,17 @@ def library(ctx,
print_opts = {
'labels': verbose,
}
DONE_ACTION = False
if bootstrap:
DONE_ACTION = True
action_bootstrap(verbose)
printDebug("Tip: you can now load an ontology by typing `ontospy -l`",
"important")
# raise SystemExit(1)
elif cache:
DONE_ACTION = True
action_cache_reset()
elif directory:
......@@ -199,12 +202,12 @@ def library(ctx,
elif save:
if filepath:
DONE_ACTION = True
action_import(filepath[0], verbose)
else:
click.secho(
"You provided no arguments - starting web import wizard..",
"You provided no arguments - please specify what to save..",
fg='white')
action_webimport()
raise SystemExit(1)
elif show:
......@@ -212,6 +215,7 @@ def library(ctx,
filename = action_listlocal(all_details=True)
if filename:
DONE_ACTION = True
g = get_pickled_ontology(filename)
if not g:
g = do_pickle_ontology(filename)
......@@ -221,9 +225,12 @@ def library(ctx,
click.echo(ctx.get_help())
return
eTime = time.time()
tTime = eTime - sTime
printDebug("\n-----------\n" + "Time: %0.2fs" % tTime, "comment")
if DONE_ACTION:
eTime = time.time()
tTime = eTime - sTime
printDebug("\n-----------\n" + "Time: %0.2fs" % tTime, "comment")
else:
printDebug("Goodbye", "comment")
##
......@@ -281,8 +288,8 @@ def shell(sources=None):
@click.option('-f', '--output_format', default='turtle')
# @click.argument('output_format', nargs=1)
@click.pass_context
def serialize(ctx, source, output_format):
"""Output a different RDF serialization for a given source.
def serial(ctx, source, output_format):
"""Serialize an RDF graph to a format of choice.
"""
verbose = ctx.obj['VERBOSE']
sTime = ctx.obj['STIME']
......@@ -322,12 +329,19 @@ def serialize(ctx, source, output_format):
help=
'JSONLD: util for testing a json-ld file using the online playground tool.'
)
@click.option(
'--discover',
'-d',
is_flag=True,
help='DISCOVER: find ontologies in online repositories like LOV or Prefix.cc'
)
@click.argument('filepath', nargs=-1)
@click.pass_context
def utils(
ctx,
filepath=None,
jsonld=False,
discover=False,
):
"""Miscellaneous utilities.
"""
......@@ -347,7 +361,9 @@ def utils(
filepath = filepath[0]
action_jsonld_playground(filepath, verbose)
DONE_ACTION = True
elif discover:
DONE_ACTION = True
action_webimport()
else:
click.secho("You haven't specified any utils command.")
click.echo(ctx.get_help())
......
......@@ -30,7 +30,9 @@ except ImportError:
try:
import urllib2
except ImportError:
import urllib as urllib2
print("python3")
import urllib.request
from urllib.request import urlopen
try:
from urllib import quote # Python 2.X
......@@ -219,14 +221,21 @@ def action_import(location, verbose=True):
# 1) extract file from location and save locally
ONTOSPY_LOCAL_MODELS = get_home_location()
fullpath = ""
try:
if location.startswith("www."): #support for lazy people
location = "http://%s" % str(location)
if location.startswith("http"):
# print("here")
print("here")
headers = {'Accept': "application/rdf+xml"}
req = urllib2.Request(location, headers=headers)
res = urllib2.urlopen(req)
try:
# Py2
req = urllib2.request(location, headers=headers)
res = urllib2.urlopen(req)
except:
# Py3
req = urllib.request.Request(location, headers=headers)
res = urlopen(req)
final_location = res.geturl() # after 303 redirects
printDebug("Saving data from <%s>" % final_location, "green")
# filename = final_location.split("/")[-1] or final_location.split("/")[-2]
......@@ -239,7 +248,7 @@ def action_import(location, verbose=True):
# print("==DEBUG", final_location, "**", filename,"**", fullpath)
file_ = open(fullpath, 'w')
file_ = open(fullpath, 'wb')
file_.write(res.read())
file_.close()
else:
......@@ -384,7 +393,10 @@ def _import_LOV(
ontouri = options[_id - 1]['uri']
print(Fore.RED + "\n---------\n" + ontouri +
"\n---------" + Style.RESET_ALL)
action_import(ontouri)
action_analyze([ontouri])
if click.confirm(
'=====\nDo you want to save to your local library?'):
action_import(ontouri)
except:
print("Error retrieving file. Import failed.")
continue
......@@ -431,7 +443,9 @@ def _import_PREFIXCC(keyword=""):
ontouri = options[_id - 1][1]
print(Fore.RED + "\n---------\n" + ontouri + "\n---------" +
Style.RESET_ALL)
action_import(ontouri)
action_analyze([ontouri])
if click.confirm('=====\nDo you want to save to your local library?'):
action_import(ontouri)
except:
print("Error retrieving file. Import failed.")
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment