How to use ontospy - 10 common examples

To help you get started, we’ve selected a few ontospy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lambdamusic / Ontospy / ontospy / core / actions.py View on Github external
filename = location.split("/")[-1] or location.split("/")[-2]
                fullpath = ONTOSPY_LOCAL_MODELS + "/" + filename
                shutil.copy(location, fullpath)
            else:
                raise ValueError('The location specified is not a file.')
        # print("Saved local copy")
    except:
        printDebug(
            "Error retrieving file. Please make sure <%s> is a valid location."
            % location, "important")
        if os.path.exists(fullpath):
            os.remove(fullpath)
        return None

    try:
        g = Ontospy(fullpath, verbose=verbose)
        # printDebug("----------")
    except:
        g = None
        if os.path.exists(fullpath):
            os.remove(fullpath)
        printDebug(
            "Error parsing file. Please make sure %s contains valid RDF." %
            location, "important")

    if g:
        printDebug("Caching...", "red")
        do_pickle_ontology(filename, g)
        printDebug("----------\n...completed!", "important")

    # finally...
    return g
github lambdamusic / Ontospy / ontospy / xxx_main.py View on Github external
elif web:
        action_webimport()
        # raise SystemExit(1)

    elif shell:
        from extras.shell import launch_shell
        launch_shell(sources)

    else:
        if sources or (sources and endpoint):
            for x in sources:
                click.secho("Parsing %s..." % str(x), fg='white')

            if endpoint:
                g = Ontospy(sparql_endpoint=sources[0], verbose=verbose)
                printDebug("Extracting classes info")
                g.build_classes()
                printDebug("..done")
                printDebug("Extracting properties info")
                g.build_properties()
                printDebug("..done")
            else:
                g = Ontospy(uri_or_path=sources, verbose=verbose)

            shellPrintOverview(g, print_opts)

        else:
            click.echo(ctx.get_help())
            return

    # finally: print(some stats.... )
github lambdamusic / Ontospy / ontospy / core / main-manager.py View on Github external
# reset local stuff
	if opts._delete:
		res = ontospy.actions_delete()
		raise SystemExit(1)

	# reset local stuff
	if opts.erase:
		ontospy.action_erase()
		raise SystemExit(1)

	# cache local ontologies
	if opts.cache:
		sTime = time.time()
		ontospy.action_cache()
		# finally: print(some stats....)
		eTime = time.time()
		tTime = eTime - sTime
		printDebug("-" * 10)
		printDebug("Time:	   %0.2fs" %  tTime, "comment")
		raise SystemExit(1)
github lambdamusic / Ontospy / ontospy / core / main-manager.py View on Github external
if _location.endswith("/"):
			# dont need the final slash
			_location = _location[:-1]
		output = ontospy.action_update_library_location(_location)
		if output:
			printDebug("Note: no files have been moved or deleted (this has to be done manually)", "comment")
			printDebug("----------\n" + "New location: '%s'" % _location, "important")

		else:
			printDebug("----------\n" + "Please specify an existing folder path.", "important")
		raise SystemExit(1)


	# reset local stuff
	if opts._delete:
		res = ontospy.actions_delete()
		raise SystemExit(1)

	# reset local stuff
	if opts.erase:
		ontospy.action_erase()
		raise SystemExit(1)

	# cache local ontologies
	if opts.cache:
		sTime = time.time()
		ontospy.action_cache()
		# finally: print(some stats....)
		eTime = time.time()
		tTime = eTime - sTime
		printDebug("-" * 10)
		printDebug("Time:	   %0.2fs" %  tTime, "comment")
github lambdamusic / Ontospy / ontospy / core / main-manager.py View on Github external
printDebug("Note: no files have been moved or deleted (this has to be done manually)", "comment")
			printDebug("----------\n" + "New location: '%s'" % _location, "important")

		else:
			printDebug("----------\n" + "Please specify an existing folder path.", "important")
		raise SystemExit(1)


	# reset local stuff
	if opts._delete:
		res = ontospy.actions_delete()
		raise SystemExit(1)

	# reset local stuff
	if opts.erase:
		ontospy.action_erase()
		raise SystemExit(1)

	# cache local ontologies
	if opts.cache:
		sTime = time.time()
		ontospy.action_cache()
		# finally: print(some stats....)
		eTime = time.time()
		tTime = eTime - sTime
		printDebug("-" * 10)
		printDebug("Time:	   %0.2fs" %  tTime, "comment")
		raise SystemExit(1)
github lambdamusic / Ontospy / ontospy / core / main-manager.py View on Github external
printDebug("OntoSpy " + ontospy.VERSION, "important")
	printDebug("Local library: '%s'" % ontospy.get_home_location())
	printDebug("------------")
	opts, args = parse_options()

	if not opts._setup:
		ontospy.get_or_create_home_repo()

	# move local lib
	if opts._setup:
		_location = args[0]
		if _location.endswith("/"):
			# dont need the final slash
			_location = _location[:-1]
		output = ontospy.action_update_library_location(_location)
		if output:
			printDebug("Note: no files have been moved or deleted (this has to be done manually)", "comment")
			printDebug("----------\n" + "New location: '%s'" % _location, "important")

		else:
			printDebug("----------\n" + "Please specify an existing folder path.", "important")
		raise SystemExit(1)


	# reset local stuff
	if opts._delete:
		res = ontospy.actions_delete()
		raise SystemExit(1)

	# reset local stuff
	if opts.erase:
github lambdamusic / Ontospy / ontospy / core / main-manager.py View on Github external
def main():
	""" command line script """

	printDebug("OntoSpy " + ontospy.VERSION, "important")
	printDebug("Local library: '%s'" % ontospy.get_home_location())
	printDebug("------------")
	opts, args = parse_options()

	if not opts._setup:
		ontospy.get_or_create_home_repo()

	# move local lib
	if opts._setup:
		_location = args[0]
		if _location.endswith("/"):
			# dont need the final slash
			_location = _location[:-1]
		output = ontospy.action_update_library_location(_location)
		if output:
			printDebug("Note: no files have been moved or deleted (this has to be done manually)", "comment")
			printDebug("----------\n" + "New location: '%s'" % _location, "important")

		else:
			printDebug("----------\n" + "Please specify an existing folder path.", "important")
		raise SystemExit(1)
github lambdamusic / Ontospy / ontospy / extras / import_web.py View on Github external
def parse_options():
	"""
	parse_options() -> opts, args

	Parse any command-line options given returning both
	the parsed options and arguments.

	https://docs.python.org/2/library/optparse.html

	"""

	parser = optparse.OptionParser(usage=USAGE, version=ontospy.VERSION)

	parser.add_option("-a", "--all",
			action="store_true", default=False, dest="all",
			help="Show all entries found by querying http://prefix.cc/popular/all.")

	parser.add_option("-q", "",
			action="store", type="string", default="", dest="query",
			help="A query string used to match the catalog entries.")

	opts, args = parser.parse_args()

	if not opts.all and not opts.query:
		parser.print_help()
		# sys.exit(0)

	return opts, args
github lambdamusic / Ontospy / ontospy / viz / scripts / export_all.py View on Github external
if outputpath:
        if not(os.path.exists(outputpath)) or not (os.path.isdir(outputpath)):
            click.secho("WARNING: the -o option must include a valid directory path.", fg="red")
            sys.exit(0)
    else:
        from os.path import expanduser
        home = expanduser("~")
        outputpath = os.path.join(home, "ontospy-viz-multi")

    if source:
        click.secho("WARNING: not implemented yet. Only local repo can be exported.", fg="red")
        sys.exit(0)
    else:
        click.secho("Exporting the local library: '%s'" % get_home_location(), fg="green")

    report_pages = []

    for onto_name in get_localontologies():

        full_uri = os.path.join(get_home_location(), onto_name)
        if theme=="random":
            _theme = random_theme()
        else:
            _theme = theme
        click.secho("Onto: <%s> Theme: '%s'" % (onto_name, _theme), fg="green")

        printDebug("Loading graph...", dim=True)
        g = Ontospy(os.path.join(get_home_location(), onto_name), verbose=verbose)

        printDebug("Building visualization...", dim=True)
github lambdamusic / Ontospy / ontospy / viz / scripts / export_all.py View on Github external
else:
        from os.path import expanduser
        home = expanduser("~")
        outputpath = os.path.join(home, "ontospy-viz-multi")

    if source:
        click.secho("WARNING: not implemented yet. Only local repo can be exported.", fg="red")
        sys.exit(0)
    else:
        click.secho("Exporting the local library: '%s'" % get_home_location(), fg="green")

    report_pages = []

    for onto_name in get_localontologies():

        full_uri = os.path.join(get_home_location(), onto_name)
        if theme=="random":
            _theme = random_theme()
        else:
            _theme = theme
        click.secho("Onto: <%s> Theme: '%s'" % (onto_name, _theme), fg="green")

        printDebug("Loading graph...", dim=True)
        g = Ontospy(os.path.join(get_home_location(), onto_name), verbose=verbose)

        printDebug("Building visualization...", dim=True)
        onto_name_safe = slugify(unicode(onto_name))
        onto_outputpath = os.path.join(outputpath, onto_name_safe )
        # note: single static files output path
        static_outputpath = os.path.join(outputpath, "static" )
        # v = KompleteViz(g, theme=_theme)
        v = KompleteVizMultiModel(g, theme=_theme, static_url="../static/", output_path_static=static_outputpath)