我是新手,我必须使用曼彻斯特OWL语法为具有类似soduku属性的网格建模.
我一直在寻找,但我似乎无法找到一种方法来制作一个公理,说"每列必须有4个单元格,并且必须具有这些值中的每一个".如在,假设4x1列,每个单元格必须包含一个数字,列必须包含所有数字[1:4].
我已经设置了一些对象,数据属性和对象属性,我将在这里留下.我将完整的.owl文件留在这里,以便可以加载,从而更容易提供帮助.
所有帮助都非常感谢.
Prefix: dc: <http://purl.org/dc/elements/1.1/>
Prefix: owl: <http://www.w3.org/2002/07/owl#>
Prefix: rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Prefix: rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix: GridTest: <http://www.semanticweb.org/existance/ontologies/2017/4/GridTest#>
Prefix: xml: <http://www.w3.org/XML/1998/namespace>
Prefix: xsd: <http://www.w3.org/2001/XMLSchema#>
Ontology: <http://www.semanticweb.org/existance/ontologies/2017/4/GridTest>
Datatype: xsd:int
Datatype: xsd:integer
ObjectProperty: GridTest:hasCell
SubPropertyOf:
GridTest:hasRelation
Domain:
GridTest:Grid
InverseOf:
GridTest:isCellOf
ObjectProperty: GridTest:hasColum
SubPropertyOf:
GridTest:hasRelation
Domain:
GridTest:Grid
Range:
GridTest:Grid
InverseOf:
GridTest:isColumOf
ObjectProperty: GridTest:hasRelation
ObjectProperty: GridTest:isCellOf
InverseOf:
GridTest:hasCell
ObjectProperty: GridTest:isColumOf
InverseOf:
GridTest:hasColum
DataProperty: GridTest:hasValue
Characteristics:
Functional
Domain:
GridTest:Cell
Range:
{"1"^^xsd:int , "2"^^xsd:int , "3"^^xsd:int , "4"^^xsd:int}
Class: GridTest:Cell
SubClassOf:
GridTest:Grid,
GridTest:hasValue exactly 1 …Run Code Online (Sandbox Code Playgroud) 假设我有两个数组
x = [1,2,3]
y = [0,1,0]
Run Code Online (Sandbox Code Playgroud)
我需要按元素划分数组,因此使用numpy.我的问题是实施了"安全部门".做的时候:
np.divide(x,y).tolist()
Run Code Online (Sandbox Code Playgroud)
我得到输出:
[0.0, 2.0, 0.0]
Run Code Online (Sandbox Code Playgroud)
我的这个问题是我需要它来返回不为0时,除以0,使理想输出的元素:
[1.0, 2.0, 3.0]
Run Code Online (Sandbox Code Playgroud)
使用numpy有没有解决方法?手动定义一个函数来执行此操作,是否有任何优化的方法来执行此操作,而不进行自定义除法功能(如下所示)并在每对元素上使用它?
def mydiv(x, y):
if y == 0:
return x
else:
return x / y
Run Code Online (Sandbox Code Playgroud)
注意:我担心优化的原因是这将在云中运行,因此资源有限,并且当拥有300多个元素阵列时,这样做根本不是最佳的.
我在以下练习中遇到问题:
编写一个接收三个Ints的函数,如果它们都是正数则求和,否则返回0(零).
我所做的是以下内容:
sum' :: int -> int -> int -> int
sum' x y z = if x >= 0, y >= 0, z >= 0 then x+y+z else 0
Run Code Online (Sandbox Code Playgroud)
我不知道如何使一个多个条件,如果,不知道这是否与逻辑"连接器"(如完成||或&&在Java中),或者如果在以类似的方式,我写的代码来完成.
所以我遇到了一些变量类型的问题.
getOrdenado :: (String,Int,String,Int,Int) -> Int
getOrdenado (_,_,_,a,_) = a
listaOrdenado :: [(String,Int,String,Int,Int)] -> [Int]
listaOrdenado xs = map getOrdenado xs
Run Code Online (Sandbox Code Playgroud)
getOrdenado从元组列表中包含的元组中获取某个Int值,listaOrdenado创建所有thoose特定Int的列表.
该函数应该在以下列表中起作用:
firma = [("Ana", 30, "RH", 1500, 3), ("Rui", 40, "Vendas", 1000, 2),
("Luis", 45, "RH", 3333, 5), ("Maria", 55, "Admin", 2000, 4)]
Run Code Online (Sandbox Code Playgroud)
但每当我尝试使用此列表运行listaOrdenado时,我会收到以下错误
Couldn't match type `Integer' with `Int'
Expected type: [(String, Int, String, Int, Int)]
Actual type: [([Char], Integer, [Char], Integer, Integer)]
In the first argument of …Run Code Online (Sandbox Code Playgroud) 我在以下练习中遇到了一些问题:
我应该编写一个函数,即3个数字,xyn,x和y分别是列表推导的底部和上限,n是理解所具有的分区数.
例如:
?> partition 10 20 4
[10.0, 12.5, 15.0, 17.5, 20.0]
Run Code Online (Sandbox Code Playgroud)
我所做的是以下内容:
partition :: Double -> Double -> Double -> [Double]
partition x y n = [a+b | b = (y-x) / n , a -> [x,b..y]]
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我不能确定,因为当我尝试运行它,我收到以下错误消息的理解,里面b变量的值:
parse error on input `='
Run Code Online (Sandbox Code Playgroud)
注意:这应该是一个初学者练习,这应该有一个简单的解决方案
我在进行以下练习时遇到问题:
利用列表理解,定义具有以下签名的函数:
reproduce :: [Int] -> [Int]
Run Code Online (Sandbox Code Playgroud)
此函数通过x副本自身交换列表中的每个数字.
例如:
input: reproduce[3,5,1]
output: [3,3,3,5,5,5,5,5,1]
Run Code Online (Sandbox Code Playgroud)
我做了以下事情:
reproduce :: [Int] -> [Int]
reproduce xs = [ x | x <- [1,2..10 ] , x `elem` xs , replicate x x ]
Run Code Online (Sandbox Code Playgroud)
我的想法是让x属于一个小间隔,x必须是原始列表的一个元素,所以使用elemx只会在它确实属于原始列表时添加,并复制x,x次,以获得x自己的副本.
当我尝试加载此功能时,我收到以下错误消息:
Couldn't match expected type `Bool' with actual type `[Int]'
In the return type of a call of `replicate'
In the expression: replicate x x
In a stmt of a list comprehension: replicate x x
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个错误,我假设它与elem部件有关但我不知道是什么.
注意:这是初学者练习,因此应该以简单的方式解决.
我在进行以下练习时遇到问题:
我必须创建一个名为addDigit的函数,它接受两个Int,第二个在0到9之间,并返回一个Int,它是第一个Int,后跟第二个.
例:
输入: addDigit (-123) 4
输出: -1234
我试过的是以下内容:
addDigit :: Int -> Int -> Int
addDigit x y = x ++ y
Run Code Online (Sandbox Code Playgroud)
我得到它不起作用,因为++关键字只适用于字符串,字符和列表(我认为),这应该以一种简单的方式解决,而不会将Int更改为字符串或任何其他变量,但我根本不了解如何做到这一点.
我在进行以下练习时遇到问题:
我应该反转列表中的所有元素,除了第一个元素,列表的第一个元素必须保持在原始位置.
正确的例子:
input: rvrsTail [1,2,3,4,5]
output [1,5,4,3,2]
Run Code Online (Sandbox Code Playgroud)
到目前为止我做了什么:
rvrsTail :: [x] -> [x]
rvrsTail xs = reverse ( tail xs)
Run Code Online (Sandbox Code Playgroud)
这确实反转了列表的尾部,但删除了第一个元素,因为我无法将第一个元素存储在变量中,所以我似乎无法理解如何解决这个问题.
错误输出:
input: rvrsTail [1,2,3,4,5]
output [5,4,3,2]
Run Code Online (Sandbox Code Playgroud)
由于这应该是初学者的练习,解决方案应该很简单.