Beispiel #1
0
def extend_inferred_knowledge(in_files, out_file):
    '''Uses the RDFClosure reasoner to create
    explicit triples from the inferred knowledge 
    n in_files and saves the complete extensional
    dataset in out_file.
    Note: RDFClosure - http://www.ivan-herman.net/Misc/2008/owlrl/
    '''
    assert type(in_files) in [list, set]
    class Options:
        sources = None
        text = None
        owlClosure = "yes"
        rdfsClosure = "yes"
        owlExtras = "no"
        axioms = False
        daxioms = False
        format = "rdfxml"
        iformat = "auto"
        trimming = False
    
    options = Options()
    options.sources = in_files
    convert_graph(options, destination=out_file)
Beispiel #2
0
def extend_inferred_knowledge(in_files, out_file):
    '''Uses the RDFClosure reasoner to create
    explicit triples from the inferred knowledge 
    n in_files and saves the complete extensional
    dataset in out_file.
    Note: RDFClosure - http://www.ivan-herman.net/Misc/2008/owlrl/
    '''
    assert type(in_files) in [list, set]

    class Options:
        sources = None
        text = None
        owlClosure = "yes"
        rdfsClosure = "yes"
        owlExtras = "no"
        axioms = False
        daxioms = False
        format = "rdfxml"
        iformat = "auto"
        trimming = False

    options = Options()
    options.sources = in_files
    convert_graph(options, destination=out_file)
Beispiel #3
0
def main():
    parser = OptionParser(usage="%prog [options] fname1 fname2 ...")
    parser.disable_interspersed_args()

    # The 'text' field is not used in the command line, but the CGI environment uses it. This means that there
    # is no option to change that, but is added to the final option structure
    parser.set_defaults(format=TURTLE,
                        owlClosure="no",
                        rdfsClosure="no",
                        owlExtras="no",
                        axioms="no",
                        daxioms="no",
                        iformat=AUTO,
                        trimming="no",
                        maximal="no",
                        text=None)

    parser.add_option(
        "-f",
        "--file",
        type="string",
        dest="source",
        help=
        "input file; should be a .rdf or .ttl file, for RDF/XML or Turtle, respectively. If "
        "missing, or if the value is '-' then standard input is used. Usage of this options is not "
        "really necessary, the fname in the command lines refer to files by themselves"
    )

    parser.add_option(
        "--owlrl",
        action="store",
        dest="owlClosure",
        choices=["yes", "no"],
        help=
        "execute OWL RL closure; argument must be yes|no [default: %default]")

    parser.add_option("-w",
                      action="store_const",
                      dest="owlClosure",
                      const="yes",
                      help="OWL-RL is executed; shorthand for --owlrl=yes")

    parser.add_option(
        "--rdfs",
        action="store",
        dest="rdfsClosure",
        choices=["yes", "no"],
        help="execute RDFS closure; argument must be yes|no [default: %default]"
    )

    parser.add_option("-r",
                      action="store_const",
                      dest="rdfsClosure",
                      const="yes",
                      help="RDFS is executed; shorthand for --rdfs=yes")

    parser.add_option(
        "--extras",
        action="store",
        dest="owlExtras",
        choices=["yes", "no"],
        help=
        "additional owl features added; argument must be yes|no [default: %default]"
    )

    parser.add_option(
        "-e",
        action="store_const",
        dest="owlExtras",
        const="yes",
        help=
        "additional owl features added; shorthand for --extras=yes [default: %default]"
    )

    parser.add_option(
        "--axioms",
        action="store",
        dest="axioms",
        choices=["yes", "no"],
        help="axiomatic triples; argument must be yes|no [default: %default]")

    parser.add_option(
        "-a",
        action="store_const",
        dest="axioms",
        const="yes",
        help=
        "add axiomatic triples; shorthand for --axioms=yes [default: %default]"
    )

    parser.add_option(
        "--daxioms",
        action="store",
        dest="daxioms",
        choices=["yes", "no"],
        help=
        "datatype axiomatic triples; argument must be true|false [default: %default]"
    )

    parser.add_option(
        "-d",
        action="store_const",
        dest="daxioms",
        const="yes",
        help=
        "add axiomatic triples; shorthand for --daxioms=yes [default: %default]"
    )

    parser.add_option(
        "--trimming",
        action="store",
        dest="trimming",
        choices=["yes", "no"],
        help=
        "trim the output of OWL 2 RL and extension; 'yes' is ineffective unless --extras=yes  "
        "[default: %default]")

    parser.add_option(
        "-m",
        "--maximal",
        action="store_const",
        dest="maximal",
        const="yes",
        help=
        "maximal possibilities switched on: RDFS, OWL with extensions, and with trimming"
    )

    parser.add_option(
        "-t",
        action="store_const",
        dest="trimming",
        const="yes",
        help=
        "trim the output of OWL 2 RL and extension; shorthand for --trimming=yes "
        "[default: %default]")

    parser.add_option(
        "-o",
        "-s",
        "--serialization",
        "--syntax",
        action="store",
        dest="format",
        choices=[TURTLE, JSON, RDFXML],
        help=
        "output format; argument must be turtle|json|xml [default: %default]")

    parser.add_option(
        "-i",
        "--input_syntax",
        action="store",
        dest="iformat",
        choices=[AUTO, TURTLE, JSON, RDFA, RDFXML],
        help=
        "format of input; argument must be auto|turtle|xml|rdfa|json [default: %default]; auto "
        "means that file suffix defines the format. This flag is valid for all input files."
    )

    (options, args) = parser.parse_args()
    if options.source is None:
        options.sources = []
    else:
        options.sources = [options.source]

    if len(args) > 0:
        options.sources += args

    if len(options.sources) == 0:
        # the default mechanism, ie, to use standard input
        options.sources = ["-"]

    if options.maximal == "yes":
        options.trimming = "yes"
        options.owlClosure = "yes"
        options.owlExtras = "yes"

    print(convert_graph(options))
Beispiel #4
0
def main() :
			
	parser = OptionParser(usage="%prog [options] fname1 fname2 ...")
	parser.disable_interspersed_args()
	
	# The 'text' field is not used in the command line, but the CGI environment uses it. This means that there
	# is no option to change that, but is added to the final option structure
	parser.set_defaults(format=TURTLE, owlClosure="yes", rdfsClosure="no", owlExtras="no", axioms="no", daxioms="no", iformat=AUTO, trimming="no", text=None)
	
	parser.add_option("-f", "--file", type="string", dest="source", 
		               help="input file; should be a .rdf or .ttl file, for RDF/XML or Turtle, respectively. If missing, or if the value is '-' then standard input is used. Usage of this options is not really necessary, the fname in the command lines refer to files by themselves")
	
	parser.add_option("--owlrl", action="store", dest="owlClosure", choices=["yes","no"], 
					   help="execute OWL RL closure; argument must be yes|no [default: %default]")
	
	parser.add_option("-w", action="store_const", dest="owlClosure", const="yes",
		               help="OWL-RL is executed; shorthand for --owlrl=yes")
	
	parser.add_option("--rdfs", action="store", dest="rdfsClosure", choices=["yes","no"], 
					   help="execute RDFS closure; argument must be yes|no [default: %default]")

	parser.add_option("-r", action="store_const", dest="rdfsClosure", const="yes",
		               help="RDFS is executed; shorthand for --rdfs=yes")

	parser.add_option("--extras", action="store", dest="owlExtras", choices=["yes","no"], 
					   help="additional owl features added; argument must be yes|no [default: %default]")

	parser.add_option("-e", action="store_const", dest="owlExtras", const="yes",
		               help="additional owl features added; shorthand for --extras=yes [default: %default]")

	parser.add_option("--axioms", action="store", dest="axioms", choices=["yes","no"], 
					   help="axiomatic triples; argument must be yes|no [default: %default]")
	
	parser.add_option("-a", action="store_const", dest="axioms", const="yes",
		               help="add axiomatic triples; shorthand for --axioms=yes [default: %default]")

	parser.add_option("--daxioms", action="store", dest="daxioms", choices=["yes","no"], 
					   help="datatype axiomatic triples; argument must be true|false [default: %default]")
	
	parser.add_option("-d", action="store_const", dest="daxioms", const="yes",
		               help="add axiomatic triples; shorthand for --daxioms=yes [default: %default]")

	parser.add_option("--trimming", action="store", dest="trimming", choices=["yes","no"], 
					   help="trim the output of OWL 2 RL and extension; 'yes' is ineffective unless --extras=yes  [default: %default]")

	parser.add_option("-t", action="store_const", dest="trimming", const="yes",
		               help="trim the output of OWL 2 RL and extension; shorthand for --trimming=yes [default: %default]")
	
	parser.add_option("-o", "-s", "--serialization", "--syntax", action="store", dest="format", choices=[TURTLE,JSON,RDFXML], 
					   help="output format; argument must be turtle|json|xml [default: %default]")
	
	parser.add_option("-i", "--input_syntax", action="store", dest="iformat", choices=[AUTO,TURTLE,RDFXML],
					   help="format of intput; argument must be auto|turtle|xml [default: %default]; auto means that file suffix defines the format. This flag is valid for all input files.")

	(options,args) = parser.parse_args()
	if options.source == None :
		options.sources = []
	else :
		options.sources = [options.source]
		
	if len(args) > 0 :
		options.sources += args
		
	if len(options.sources) == 0 :
		# the default mechanism, ie, to use standard input
		options.sources = ["-"]
			
	print convert_graph(options)
Beispiel #5
0
        print('<dt>Axiomatic triples added:</dt><dd>%s</dd>' % self.axioms)
        print('<dt>Datatype Axiomatic triples added:</dt><dd>%s</dd>' %
              self.daxioms)
        if self.text is not None:
            print('<dt>Turtle code added to the graph:</dt>')
        print('<dl>')
        if self.text is not None:
            print(cgi.escape(self.text).replace('\n', '<br/>'))


# ---------------------------------------------------------------------------------------------------------------------

options = Options(form)

try:
    retval = convert_graph(options)
    if options.format == TURTLE:
        print('Content-Type: text/turtle; charset=utf-8')
    else:
        print('Content-Type: application/rdf+xml; charset=utf-8')
    print()
    print(retval)
except:
    (typ, value, traceback) = sys.exc_info()
    print('Content-type: text/html; charset=utf-8')
    print('Status: 400 Invalid Input')
    print()
    print("<html>")
    print("<head>")
    print("<title>Error in RDF Closure processing</title>")
    print("</head><body>")
Beispiel #6
0
		print '<dt>Output format:</dt><dd>%s</dd>' % self.format
		print '<dt>OWL 2 RL Processing:</dt><dd>%s</dd>' % self.owlClosure
		print '<dt>RDFS Processing:</dt><dd>%s</dd>' % self.rdfsClosure
		print '<dt>Extra OWL Processing:</dt><dd>%s</dd>' % self.owlExtras
		print '<dt>Axiomatic triples added:</dt><dd>%s</dd>' % self.axioms
		print '<dt>Datatype Axiomatic triples added:</dt><dd>%s</dd>' % self.daxioms
		if self.text != None: print '<dt>Turtle code added to the graph:</dt>'
		print '<dl>'
		if self.text != None :
			print cgi.escape(self.text).replace('\n','<br/>')

##-----------------------------------------------------------------------------------------------------------------------------------
options = Options(form)

try :
	retval = convert_graph(options)
	if options.format == TURTLE :
		print 'Content-Type: text/turtle; charset=utf-8'
	else :
		print 'Content-Type: application/rdf+xml; charset=utf-8'
	print
	print retval
except :
	(type,value,traceback) = sys.exc_info()
	print 'Content-type: text/html; charset=utf-8'
	print 'Status: 400 Invalid Input'
	print
	print "<html>"
	print "<head>"
	print "<title>Error in RDF Closure processing</title>"
	print "</head><body>"