Skip to content

Commit

Permalink
fix(interactive): Update README.md for compiler and experiment queries (
Browse files Browse the repository at this point in the history
#4357)

<!--
Thanks for your contribution! please review
https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before
opening an issue.
-->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

As titled. 

## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

Fixes
  • Loading branch information
BingqingLyu authored Dec 12, 2024
1 parent 3d98c77 commit c02b1d7
Show file tree
Hide file tree
Showing 81 changed files with 662 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
MATCH (message:COMMENT)
WHERE message.creationDate < $datetime
WITH count(message) AS totalMessageCount

MATCH (message:COMMENT)
WHERE message.creationDate < $datetime
AND message.length > 0
WITH
totalMessageCount,
message,
date(datetime({epochMillis: message.creationDate})) AS date
WITH
totalMessageCount,
date.year AS year,
CASE
WHEN 'POST' in labels(message) THEN 0
ELSE 1
END AS isComment,
CASE
WHEN message.length < 40 THEN 0
WHEN message.length < 80 THEN 1
WHEN message.length < 160 THEN 2
ELSE 3
END AS lengthCategory,
count(message) AS messageCount,
sum(message.length) / count(message) AS averageMessageLength,
count(message.length) AS sumMessageLength

RETURN
year,
isComment,
lengthCategory,
messageCount,
averageMessageLength,
sumMessageLength,
messageCount / totalMessageCount AS percentageOfMessages
ORDER BY
year DESC,
isComment ASC,
lengthCategory ASC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MATCH (p1:PERSON {id : $personId})-[:KNOWS*1..4]-(expert:PERSON),
(expert)-[:ISLOCATEDIN]->(:PLACE)-[:ISPARTOF]->(country:PLACE {name: $country}),
(expert)<-[:HASCREATOR]-(message)-[:HASTAG]->(:TAG)-[:HASTYPE]->(:TAGCLASS {name: $tagClass})
WITH DISTINCT expert, message
MATCH (message)-[:HASTAG]->(tag:TAG)
RETURN
expert.id as id,
tag.name as name,
count(message) AS messageCount
ORDER BY
messageCount DESC,
name ASC,
id ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MATCH (a:PERSON)-[:ISLOCATEDIN]->(:PLACE)-[:ISPARTOF]->(country:PLACE {name: $country}),
(b)-[:ISLOCATEDIN]->(:PLACE)-[:ISPARTOF]->(country),
(c)-[:ISLOCATEDIN]->(:PLACE)-[:ISPARTOF]->(country),
(a)-[k1:KNOWS]-(b:PERSON),
(b)-[k2:KNOWS]-(c:PERSON),
(c)-[k3:KNOWS]-(a)
WHERE a.id < b.id
AND b.id < c.id
AND $startDate <= k1.creationDate AND k1.creationDate <= $endDate
AND $startDate <= k2.creationDate AND k2.creationDate <= $endDate
AND $startDate <= k3.creationDate AND k3.creationDate <= $endDate
WITH DISTINCT country, a, b
RETURN count(*) AS count;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MATCH (person:PERSON)<-[:HASCREATOR]-(message),
(message)-[:REPLYOF * 0..30]->(post:POST)
WHERE message.length < $lengthThreshold
AND message.creationDate > $startDate
AND post.language IN languages
WITH person, count(message) as msgCnt
RETURN msgCnt, count(person) as personCnt
ORDER BY
personCnt DESC,
msgCnt DESC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
MATCH (country:PLACE {name: $country})<-[:ISPARTOF]-(:PLACE)<-[:ISLOCATEDIN]-(zombie:PERSON)
WHERE zombie.creationDate < $endDate
OPTIONAL MATCH (zombie)<-[:HASCREATOR]-(message)
WHERE message.creationDate < $endDate
WITH
country,
zombie,
date(datetime({epochMillis: $endDate})) as idate,
date(datetime({epochMillis: zombie.creationDate})) as zdate,
count(message) AS messageCount
WITH
country,
zombie,
12 * (idate.year - zdate.year )
+ (idate.month - zdate.month)
+ 1 AS months,
messageCount
WHERE messageCount / months < 1
WITH
country,
collect(zombie) AS zombies
UNWIND zombies AS zombie
MATCH // Match1
(zombie)<-[:HASCREATOR]-()<-[:LIKES]-(likerZombie:PERSON)
WHERE likerZombie IN zombies
MATCH // Match2
(zombie)<-[:HASCREATOR]-()<-[:LIKES]-(likerPerson:PERSON)
WHERE likerPerson.creationDate < $endDate
WITH
zombie,
count(distinct likerZombie) AS zombieLikeCount, // Aggregate1
count(distinct likerPerson) AS totalLikeCount // Aggregate2
RETURN
zombie.id AS zid,
zombieLikeCount,
totalLikeCount,
CASE totalLikeCount
WHEN 0 THEN 0.0
ELSE zombieLikeCount / totalLikeCount
END AS zombieScore
ORDER BY
zombieScore DESC,
zid ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MATCH
(country1:PLACE {name: $country1})<-[:ISPARTOF]-(city1:PLACE)<-[:ISLOCATEDIN]-(person1:PERSON),
(country2:PLACE {name: $country2})<-[:ISPARTOF]-(city2:PLACE)<-[:ISLOCATEDIN]-(person2:PERSON),
(person1)-[knows:KNOWS]-(person2)
// Match1
MATCH (person1)<-[:HASCREATOR]-(c:COMMENT)-[:REPLYOF]->()-[:HASCREATOR]->(person2:PERSON)
WITH person1, person2, city1, 4 as score1
// Match2
MATCH (person1)-[:LIKES]->(m)-[:HASCREATOR]->(person2)
WITH person1, person2, city1, score1, 10 as score2
WITH
person1,
person2,
city1,
sum(distinct score1) as score1, // Aggregate1
sum(distinct score2) as score2 // Aggregate2
RETURN count(*);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MATCH (person1:PERSON)<-[:HASCREATOR]-(message1)-[:HASTAG]->(tag:TAG {name: $tagName})
WHERE message1.creationDate > $date
OPTIONAL MATCH (person1)-[:KNOWS]-(person2:PERSON)<-[:HASCREATOR]-(message2)-[:HASTAG]->(tag)
WHERE message2.creationDate = $date
WITH person1, count(DISTINCT message1) AS cm, count(DISTINCT person2) AS cp2
WHERE cp2 <= 4
// return count
RETURN person1, cm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MATCH
(comment)-[:HASTAG]->(tag:TAG {name: $tag}),
(comment)-[:REPLYOF]->(message2),
(message2)-[:HASTAG]->(tag),
(message1)-[:HASTAG]->(tag:TAG {name: $tag}),
(message1)-[:REPLYOF*0..10]->(post1:POST)<-[:CONTAINEROF]-(forum1:FORUM),
(forum1)-[:HASMEMBER]->(person3:PERSON)<-[:HASCREATOR]-(message2)
RETURN count(*);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MATCH (tag:TAG {name: $tag})<-[:HASINTEREST]-(person1:PERSON)-[:KNOWS]-(mutualFriend:PERSON)-[:KNOWS]-(person2:PERSON)-[:HASINTEREST]->(tag2 {name: $tag})
WHERE person1 <> person2
AND NOT (person1)-[:KNOWS]-(person2)
RETURN person1.id AS person1Id, person2.id AS person2Id, count(DISTINCT mutualFriend) AS mutualFriendCount
ORDER BY mutualFriendCount DESC, person1Id ASC, person2Id ASC
LIMIT 20;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
MATCH (tag:TAG)-[:HASTYPE]->(:TAGCLASS {name: $tagClass}), (tag:TAG)<-[:HASTAG]-(message)
WITH
tag,
CASE
WHEN message.creationDate < $dateEnd1
AND message.creationDate >= $date THEN 1
ELSE 0
END AS count1,
CASE
WHEN message.creationDate < $dateEnd2
AND message.creationDate >= $dateEnd1 THEN 1
ELSE 0
END AS count2
WITH
tag,
sum(count1) AS countWindow1,
sum(count2) AS countWindow2
RETURN
tag.name as name,
countWindow1,
countWindow2,
abs(countWindow1 - countWindow2) AS diff
ORDER BY
diff DESC,
name ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MATCH
(country:PLACE {name: $country})<-[:ISPARTOF]-()<-[:ISLOCATEDIN]-
(person:PERSON)<-[:HASMODERATOR]-(forum:FORUM)-[:CONTAINEROF]->(post:POST)<-[:REPLYOF*0..30]-(message)-[:HASTAG]->(:TAG)-[:HASTYPE]->(:TAGCLASS {name: $tagClass})
RETURN
forum.id as id,
forum.title,
forum.creationDate,
person.id as personId,
count(DISTINCT message) AS messageCount
ORDER BY
messageCount DESC,
id ASC
LIMIT 20;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
MATCH (country:PLACE)<-[:ISPARTOF]-(:PLACE)<-[:ISLOCATEDIN]-(person:PERSON)<-[:HASMEMBER]-(forum:FORUM)
WHERE forum.creationDate > $date
WITH country, forum, count(person) AS numberOfMembers
ORDER BY numberOfMembers DESC, forum.id ASC, country.id
WITH DISTINCT forum AS topForum
LIMIT 100

WITH collect(topForum) AS topForums

UNWIND topForums AS topForum2
MATCH (topForum1)-[:CONTAINEROF]->(post:POST)<-[:REPLYOF*0..30]-(message)-[:HASCREATOR]->(person:PERSON)<-[:HASMEMBER]-(topForum2:FORUM)
WITH person, message, topForum1
WHERE topForum1 IN topForums
WITH person, count(DISTINCT message) AS messageCount

RETURN
person.id AS personId,
person.firstName AS personFirstName,
person.lastName AS personLastName,
person.creationDate AS personCreationDate,
sum(messageCount) AS messageCount
ORDER BY
messageCount DESC,
person.id ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Match (tag:TAG {name: $tag})<-[:HASTAG]-(message)
OPTIONAL MATCH (message)<-[:LIKES]-(liker:PERSON)
OPTIONAL MATCH (message)<-[:REPLYOF]-(comment:COMMENT)
MATCH (message)-[:HASCREATOR]->(person:PERSON)
WITH message, person, count(distinct liker) as likeCount, count(distinct comment) as replyCount
WITH
person.id AS id,
sum(replyCount) as replyCount,
sum(likeCount) as likeCount,
count(message) as messageCount
RETURN
id,
replyCount,
likeCount,
messageCount,
1*messageCount + 2*replyCount + 10*likeCount AS score
ORDER BY
score DESC,
id ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MATCH (tag:TAG {name: $tag})<-[:HASTAG]-(message1)-[:HASCREATOR]->(person1:PERSON),
(message1)<-[:LIKES]-(person2:PERSON),
(person2)<-[:HASCREATOR]-(message2)<-[like:LIKES]-(person3:PERSON)
RETURN
person1.id,
// Using 'DISTINCT like' here ensures that each person2's popularity score is only added once for each person1
count(DISTINCT like) AS authorityScore
ORDER BY
authorityScore DESC,
person1.id ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
MATCH
(tag:TAG {name: $tag})<-[:HASTAG]-(message:COMMENT),
(message)<-[:REPLYOF]-(comment:COMMENT),
(comment:COMMENT)-[:HASTAG]->(relatedTag:TAG)
WHERE NOT (comment:COMMENT)-[:HASTAG]->(tag:TAG {name: $tag})
RETURN
relatedTag.name as name,
count(DISTINCT comment) AS count
ORDER BY
count DESC,
name ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MATCH (tag:TAG {name: $tag})
// score
OPTIONAL MATCH (tag)<-[interest:HASINTEREST]-(person:PERSON)
OPTIONAL MATCH (tag)<-[:HASTAG]-(message)-[:HASCREATOR]->(person:PERSON)
WHERE $startDate < message.creationDate
AND message.creationDate < $endDate
RETURN tag, count(person) AS totalCount;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MATCH
(person:PERSON)<-[:HASCREATOR]-(post:POST)<-[:REPLYOF*0..7]-(message)
WHERE
post.creationDate >= $startDate AND post.creationDate <= $endDate AND
message.creationDate >= $startDate AND message.creationDate <= $endDate
WITH
person,
count(distinct post) as threadCnt,
count(message) as msgCnt
RETURN
person.id as id,
person.firstName,
person.lastName,
threadCnt,
msgCnt
ORDER BY
msgCnt DESC,
id ASC
LIMIT 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
MATCH k = shortestPath((p: PERSON{id: $personId})-[:KNOWS*1..4]-(f: PERSON {firstName: $firstName}))
MATCH (f:PERSON)-[:ISLOCATEDIN]->(locationCity:PLACE)

WHERE
p <> f

OPTIONAL MATCH (f: PERSON)-[workAt:WORKAT]->(company:ORGANISATION)-[:ISLOCATEDIN]->(country:PLACE)
// append one new column <companies>
WITH
f, k, locationCity,
CASE
WHEN company is null Then null
ELSE [company.name, workAt.workFrom, country.name]
END as companies

WITH f, k, locationCity, collect(companies) as company_info

OPTIONAL MATCH (f: PERSON)-[studyAt:STUDYAT]->(university)-[:ISLOCATEDIN]->(universityCity:PLACE)
// append one new column <universities>
WITH f, k, locationCity, company_info,
CASE
WHEN university is null Then null
ELSE [university.name, studyAt.classYear, universityCity.name]
END as universities

WITH f, k, locationCity, company_info, collect(universities) as university_info

// apend one new column <distance>
WITH
f,
k,
locationCity,
company_info,
university_info,
length(k) as distance

ORDER BY distance ASC, f.lastName ASC, f.id ASC
LIMIT 20

return f.id AS friendId,
f.lastName AS friendLastName,
distance AS distanceFromPerson,
f.birthday AS friendBirthday,
f.creationDate AS friendCreationDate,
f.gender AS friendGender,
f.browserUsed AS friendBrowserUsed,
f.locationIP AS friendLocationIp,
f.email AS friendEmail,
f.language AS friendLanguage,
locationCity.name AS friendCityName,
university_info AS friendUniversities,
company_info AS friendCompanies;
Loading

0 comments on commit c02b1d7

Please sign in to comment.