forked from felixwqp/ProfPedia
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheval.py
More file actions
71 lines (58 loc) · 1.95 KB
/
Copy patheval.py
File metadata and controls
71 lines (58 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from bs4 import BeautifulSoup
import urllib
import requests
import collections
import sys
import time
import re
import os
from nltk.corpus import stopwords
def crawl_dblp(professor):
name = professor.replace("\n","").split(" ")
profname = ""
for i in range(len(name)-1):
profname += name[i]+"$"
profname += name[-1]
url = 'http://dblp.org/search/publ/api?q=' + profname + '&format=xml'
path = os.getcwd() + "/Evaluation_data/" + professor +"_dblp.txt"
save = urllib.request.urlretrieve(url, path)
file = open(path,"r")
content = file.read()
num_paper = content.count("<title>")
return num_paper
def rank(univerity, query):
# remove stop words, reform query
stop_words = stopwords.words('english')
query_word = query.replace("\n","").split(" ")
query_word = [word for word in query_word if word not in stop_words]
tmp = ""
for i in range(len(query_word)-1):
tmp += query_word[i]+" "
tmp += query_word[-1]
query = tmp
# readin professors name
uni_name = ""
for x in univerity.split(" "):
uni_name += "\ "+ x
file = open(os.getcwd() + "/universities/"+ univerity+".txt","r")
prof = file.readline().strip("\n")
professor_query = []
# search query = prof name + reformed query
while prof:
professor_query.append([prof,prof+" "+query])
prof = file.readline()
# get rank results
professor_rankscore = [[crawl_dblp(x[1]),x[0]] for x in professor_query]
professor_rankscore = sorted(professor_rankscore, reverse = True)
return professor_rankscore
testcase = open("Testcase.txt","r")
line = testcase.readline()
while line:
university, query = line.strip("\n").split(", ")
ranking = rank(university, query)
print(query)
for idx, content in enumerate(ranking[:10]):
print(idx+1, ": ", content[1].strip("\n"))
print("score: ", content[0])
print("\n")
line = testcase.readline()