我必须使用多种模式来过滤大文件。问题是我不确定使用rlike. 举个例子
df = spark.createDataFrame(
[
('www 17 north gate',),
('aaa 45 north gate',),
('bbb 56 west gate',),
('ccc 56 south gate',),
('Michigan gate',),
('Statue of Liberty',),
('57 adam street',),
('19 west main street',),
('street burger',)
],
[ 'poi']
)
df.show()
+-------------------+
| poi|
+-------------------+
| www 17 north gate|
| aaa 45 north gate|
| bbb 56 west gate|
| ccc 56 south gate|
| Michigan gate|
| Statue of Liberty|
| 57 adam street|
|19 west …Run Code Online (Sandbox Code Playgroud) 我试图在我的本地控制台中重现莎士比亚数据集和查询.我创建了节点和关系.
neo4j-sh (0)$ START theater=node:venues(theatre = 'Theatre Royal'), newcastle=node:cities(city = 'Newcastle'), bard=node:authors('firstname:William AND lastname:Shakespeare') MATCH (newcastle)<-[:IN*1..4]-(theater)<-[:VENUE]-(performance)-[:PERFORMED]->(play)<-[w:WROTE]-(bard) WHERE w.date > 1608 RETURN play;
==> MissingIndexException: Index `authors` does not exist
Run Code Online (Sandbox Code Playgroud)
没有识别作者,场地和城市索引,所以我去添加和删除索引选项卡并创建这些索引.这是屏幕转储
neo4j-sh (0)$ index --indexes
==> Node indexes:
==> venues
==> cities
==> authors
==>
==> Relationship indexes:
Run Code Online (Sandbox Code Playgroud)
但是现在,相同的查询没有错误但没有返回任何内容.我究竟做错了什么.从Web控制台创建索引的语法不是那么清楚.我究竟做错了什么?
我有多个文本,每个文本可能包含对一个或多个Web链接的引用.例如:
text1= "s@1212a as www.abcd.com asasa11".
Run Code Online (Sandbox Code Playgroud)
我如何提取:
"www.abcd.com"
Run Code Online (Sandbox Code Playgroud)
从R中的这个文本?换句话说,我希望提取以开头www和结尾的模式.com
我试图根据用户在此图中的共同兴趣来比较用户.
我知道为什么以下查询会产生重复对,但是在cypher中无法想到避免它的好方法.如果没有在密码中循环,有没有办法做到这一点?
neo4j-sh (?)$ start n=node(*) match p=n-[:LIKES]->item<-[:LIKES]-other where n <> other return n.name,other.name,collect(item.name) as common, count(*) as freq order by freq desc;
==> +-----------------------------------------------+
==> | n.name | other.name | common | freq |
==> +-----------------------------------------------+
==> | "u1" | "u2" | ["f1","f2","f3"] | 3 |
==> | "u2" | "u1" | ["f1","f2","f3"] | 3 |
==> | "u1" | "u3" | ["f1","f2"] | 2 |
==> | "u3" | "u2" | ["f1","f2"] | 2 |
==> …Run Code Online (Sandbox Code Playgroud) 我在Neo4php中创建了如下关系
$src->relateTo($dst, 'FRIENDS')
->setProperty('duration', '5')
->save();
Run Code Online (Sandbox Code Playgroud)
我希望这种关系不是指导的.如果我没有错,我们可以在Cypher中做到这一点
create n-[:FRIENDS]-m
Run Code Online (Sandbox Code Playgroud)
VS
create n-[:FRIENDS]->m
Run Code Online (Sandbox Code Playgroud)
在Neo4jphp怎么样?我们可以将"relatedTo"设置为双向关系吗?
我正在运行以下查询以在意大利吸引游客
select distinct ?poi where {?company a dbpedia-owl:Place ; rdfs:label ?poiName; dcterms:subject/skos:broader* category:Visitor_attractions_in_Italy }
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误。
Virtuoso 42000 Error TN...: Exceeded 1000000000 bytes in transitive temp memory. use t_distinct, t_max or more T_MAX_memory options to limit the search or increase the pool SPARQL query: define sql:big-data-const 0 #output-format:application/sparql-results+json define input:default-graph-uri PREFIX owl: PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: select distinct ?poi where {?company a dbpedia-owl:Place ; rdfs:label ?poiName; dcterms:subject/skos:broader* …Run Code Online (Sandbox Code Playgroud) 我有以下字符串
> str
[1] "[ { \"category\" : \"book\"} , { \"category\" : \"Movie\"} , { \"category\" : \"Brand\"}]"
Run Code Online (Sandbox Code Playgroud)
我想剥离它以获得以下向量
> a
[1] "book" "Movie" "Brand"
Run Code Online (Sandbox Code Playgroud)
我的问题是如何处理字符串中的""和\以将其传递给R中的grep或gsub.这就是我做的,我得到一个错误
> grep("^\[ \{ \\"category\\" : \\"([a-zA-Z0-9/]+)\\".*",str)
Error: '\[' is an unrecognized escape in character string starting "^\["
Run Code Online (Sandbox Code Playgroud)
我是否走在正确的轨道上?
在运行SPARQL查询和您编写的代码之间需要权衡清理结果.
复杂的查询: Pros:弄干净/有效的结果,进行清理更少的代码 Cons: 超时错误,处理时间长.
我知道有人不能概括它,但想比较梳理子查询(UNION,...),过滤器和聚合,并在超时的情况下查看哪一个是更昂贵的操作.
例如,我从日语SPARQL端点运行此查询(我删除了它的一部分).
SELECT ?film ?dblink ?filmType (group_concat(?actors ; separator = "|") AS ?actorset) (group_concat(?country ; separator = "|") AS ?countryset) (group_concat(?releaseDate ; separator = "|") AS ?releasedateset) (group_concat(?language ; separator = "|") AS ?languageset) (group_concat(?genre ; separator = "|") AS ?genreset) ?numberOfEpisodes ?numberOfSeasons
WHERE {
{?film a dbpedia-owl:Film } UNION {?film a dbpedia-owl:TelevisionShow } UNION {?film a dbpedia-owl:Cartoon } UNION {?film a dbpedia-owl:TelevisionSeason } .
{?film a ?filmType } .Filter(regex(?filmType,"(?:TelevisionSeason|Cartoon|Film|TelevisionShow)")) …Run Code Online (Sandbox Code Playgroud) 我已经安装了本地的virtuoso服务器并导入了dbpedia数据.我发现了一系列在isql中不起作用的SPARQL命令.例如,我在我的isql shell中运行了这个查询.
SPARQL SELECT ?s GROUP_CONCAT (?obj, ' ') as ?artist_list WHERE { ?s a dbpedia-owl:Single ;(dbpedia-owl:artist|dbpedia-owl:producer) ?obj } limit 10
Run Code Online (Sandbox Code Playgroud)
它首先抱怨| 在(dbpedia-owl:artist | dbpedia-owl:producer)中,然后是GROUP_CONCAT.我对Virtuoso文档进行了一些研究,并做了以下工作
EDIT1 我试图检查不同的情况,
1- group_concat
SPARQL select ?s (group_concat(?obj; separator='|') as ?artist_list) FROM <http://ja.dbpedia.org> where { ?s a dbpedia-owl:Single ; (dbpedia-owl:artist) ?obj } group by ?s limit 10;
SQL> syntax error at 'group_concat' before '('
Run Code Online (Sandbox Code Playgroud)
2-使用值
SPARQL select ?s FROM <http://ja.dbpedia.org> where { values ?sType {dbpedia-owl:Song dbpedia-owl:Single }. ?s a ?sType} limit 10;
*** Error 37000: …Run Code Online (Sandbox Code Playgroud) 假设我有以下文件
Y M C A
cambridge m a
d m v office
t mobile
Run Code Online (Sandbox Code Playgroud)
并希望将其转换为
YMCA
cambridge ma
dmv office
t mobile
Run Code Online (Sandbox Code Playgroud)
即检测所有连续的单个字符,后跟不同长度的单个空格(大于2).例如,项目'dmv office',我们应检测'dm v'并将其转换为'dmv',但会保留't mobile store'完整(只有一个字符).
是否可以在bash中执行此操作,或者我必须使用像python这样的程序来执行此操作?