综合设计——多源异构数据采集与融合应用综合实践

1. 基本信息

这个项目属于哪个课程 2023数据采集与融合
组名 冲就完事
项目简介 当我们置身于日常生活或旅途中,常会被美景所震撼,但往往难以找到合适的诗句来表达内心的感悟。为了传承中华传统文化、提升人们的诗词修养和表达能力,我们需要一个智能系统能够根据用户拍摄的照片,自动匹配相应的诗句,并为用户提供相关的学习资源。
团队成员学号 102102101田甜、102102102刘燕莹、102102103李盈盈、102102106何雯彧、102102107张锦瑶、102102110饶雯捷、102102147高宝众、102102153彭诗忠
这个项目的目标 本系统旨在实现以下功能:
a. 图片解释:基于用户上传的图片,系统能够自动识别图片内容,并提供与图片相符合的文字解释。
b. 古诗详情:用户可以选择获取与所拍图片相关的一首古诗的详细信息,包括标题、作者、内容、出处等。
c. 同韵古诗:用户可以获取与所拍图片相关的同韵古诗,以便进行进一步学习和欣赏。
d. 相似句子查询:用户可以输入关键词或句子,系统将返回与输入内容相似的古诗句子,以帮助用户寻找相关诗歌作品。
e.获取诗句相关地点地图:当诗句蕴含地址时,用户可以获取到该地点在地图上的位置
其他参考文献 Junnan Li, Dongxu Li, Silvio Savarese, Steven Hoi.BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models:arXiv:2301.12597
gitee链接: https://gitee.com/PicaPicasso/crawl_project/tree/master/综合设计——多源异构数据采集与融合应用综合实践

2. 个人分工

  • 爬取网站数据,解析爬取下来的部分数据

    • 爬取诗歌标题、作者、内容
    import requests
    import json
    import urllib.parse
    from scrapy.selector import Selector
    from bs4 import UnicodeDammit
    import sys
    
    def scrapyData(keyword):
    
        url = 'https://sou-yun.cn/QueryPoem.aspx'
        headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.47'
        }
    
        results = {}
      
        KeywordTextBox = urllib.parse.quote(keyword)  # 查找的关键字
        QueryButton = urllib.parse.quote("检索")
        param = 'KeywordTextBox=' + KeywordTextBox + '&QueryButton=' + QueryButton
        param = param.encode()
        data = requests.post(url=url,data=param,headers=headers).content
        dammit=UnicodeDammit(data,["utf-8","gbk"])
        data=dammit.unicode_markup
        selector = Selector(text=data)
    
        ResultArea = selector.xpath('//div[@id="ResultArea"]')
        if ResultArea != []:
            title = "".join(selector.xpath('//div[@id="ResultArea"]/div[1]//a[@class="poemCommentLink"]//text()').extract()).strip()
            author = "".join(selector.xpath('//div[@id="ResultArea"]/div[1]//span[@class="poemAuthor"]//text()').extract()).strip()
            poetry = "".join(selector.xpath('//div[@id="ResultArea"]/div[1]//div[@class="poemContent"]//text()').extract()).strip()
    
            detail_url_part = selector.xpath('//div[@id="ResultArea"]/div[1]//a[@class="poemCommentLink"]/@href').extract()[0]
            index = detail_url_part.rfind('=')
            id = detail_url_part[index+1:]  # 获取古诗对应的id,用于接口二、三、四的数据抓取
    
            results['title'] = title
            results['author'] = author
            results['poetry'] = poetry
            results['id'] = id
        else:
            results['title'] = ""
            results['author'] = ""
            results['poetry'] = ""
            results['id'] = ""
    
        return json.dumps(results)
    
    
    if __name__ == '__main__':
    
        result = scrapyData(sys.argv[1])
        # result = scrapyData("伏特加 琴酒")
    
        print(result)
    
    • 爬取诗歌出处和对应图片
      import requests
      import re
      import json
      import sys
    
    
      def scrapyData(id):
    
          headers = {
              'Content-Type': 'application/x-www-form-urlencoded',
              'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.47'
          }
    
          results = {}
    
          # 接口二
          provenance_url = f'https://api.sou-yun.cn/api/KanripoLinks?type=Poem&id={id}&pageNo=0'
          provenance_data = requests.get(url=provenance_url,headers=headers).text
          # 由于只爬取第一位的古诗,所以可以把后面的古诗截掉
          index = provenance_data.find('}')
          provenance_data = provenance_data[:index]
    
          # print(provenance_data)
          # s = '.*?"Book":.*?"(.*?)".*?"Volumn":.*?"(.*?)".*?"StartPage":.*?"(.*?)".*?"EndPage":.*?"(.*?)".*?"MatchedText":.*?"(.*?)".*?"PreviousText":.*?"(.*?)".*?"LaterText":.*?"(.*?)".*?"PageImages":.*?\[(.*?)\]'
          # data = re.compile(s,re.S).findall(provenance_data)
          Book = re.compile('.*?"Book":.*?"(.*?)"',re.S).findall(provenance_data)
          Book = Book[0] if Book != [] else ""
          Volumn = re.compile('.*?"Volumn":.*?"(.*?)"',re.S).findall(provenance_data)
          Volumn = Volumn[0] if Volumn != [] else ""
          StartPage = re.compile('.*?"StartPage":.*?"(.*?)"',re.S).findall(provenance_data)
          StartPage = StartPage[0] if StartPage != [] else ""
          EndPage = re.compile('.*?"EndPage":.*?"(.*?)"',re.S).findall(provenance_data)
          EndPage = EndPage[0] if EndPage != [] else ""
          MatchedText = re.compile('.*?"MatchedText":.*?"(.*?)"',re.S).findall(provenance_data)
          MatchedText = MatchedText[0] if MatchedText != [] else ""
          PreviousText = re.compile('.*?"PreviousText":.*?"(.*?)"',re.S).findall(provenance_data)
          PreviousText = PreviousText[0] if PreviousText != [] else ""
          LaterText = re.compile('.*?"LaterText":.*?"(.*?)"',re.S).findall(provenance_data)
          LaterText = LaterText[0] if LaterText != [] else ""
          PageImages = re.compile('.*?"PageImages":.*?\[(.*?)\]',re.S).findall(provenance_data)
          PageImages = PageImages[0] if PageImages != [] else ""
    
          if Book != "" and Volumn != "" and StartPage != "" and EndPage !="":
              source = Book + " " +  Volumn + "(第 " + StartPage + " - " + EndPage + " 頁)"
          else:
              source = ""
    
          if PageImages!="":
              img_urls = PageImages.split(',')
              imgSrc = 'https://c.cnkgraph.com/kanripoimgs/' + img_urls[0].strip('"')
          else:
              imgSrc = ""
          # 去除诗句中可能含有的标签数据
          pattern = r'<.*?>'
          PreviousText = re.sub(pattern, '', PreviousText)
          MatchedText = re.sub(pattern, '', MatchedText)
          LaterText = re.sub(pattern, '', LaterText)
          # 原始数据中有些空格,是为了显示数据时的段落缩进,无需删除
          # 每句诗句用\n分隔
          content = PreviousText + MatchedText + LaterText
    
          results['source'] = source
          results['imgSrc'] = imgSrc
          results['content'] = content
          return json.dumps(results)
    
    
    
      if __name__ == '__main__':
    
          result = scrapyData(sys.argv[1])
          # result = scrapyData("")
    
          print(result)
    
    
  • 寻找java调用python脚本获取数据的方法
    最终参考了这篇文章Java调用Python爬虫获取信息

  • 使用springBoot编写后端部分接口代码

    • 接口一代码
      @RequestMapping("/article")
      public Result queryArticle(@RequestBody Keywords keywords) {
          String keyword = keywords.getKeyword1() +  " " + keywords.getKeyword2() ;
          log.info("Received parameters - keyword1: {}, keyword2: {}", keywords.getKeyword1(), keywords.getKeyword2());
    
          String result_json = crawlRuner.Run("scrapyArticle.py",keyword);
          log.info(result_json);
          Article article = new Article();
          Map<String, String> map = ParseJson.parse(result_json, "author", "title","poetry","id");
          article.setAuthor(map.get("author"));
          article.setTitle(map.get("title"));
          article.setPoetry(map.get("poetry"));
          id = map.get("id");
    

// log.info("param: " + keyword);
return Result.success(article);
}

* 接口二代码
@RequestMapping("/provenance")
public Result queryProvenance(){
    String result_json = crawlRuner.Run("scrapyProvenance.py",id);
    Provenance provenance = new Provenance();
    Map<String, String> map = ParseJson.parse(result_json, "source", "imgSrc","content");
    provenance.setSource(map.get("source"));
    provenance.setImgSrc(map.get("imgSrc"));
    provenance.setContent(map.get("content"));
    log.info("provenance: " + id);
    return Result.success(provenance);
}
* 图片上传接口
@PostMapping("getKeyword")
public Result getKeyword(MultipartFile image) throws IOException {
    // 将图片保存到本地,方便python脚本读取数据
    String savePath = "C:\\Users\\25382\\Desktop\\images\\text.png";
    image.transferTo(new File(savePath));
    String result = crawlRuner.Run("getKeywords.py",savePath);
    System.out.println(result);
    log.info( "result: " + result);
    String [] keys = result.split("\\s+");
    Keywords keywords = new Keywords();
    if(keys.length ==  2){
        keywords.setKeyword1(keys[0]);
        keywords.setKeyword2(keys[1]);
    }
    else if(keys.length == 1) {
        keywords.setKeyword1(keys[0]);
        keywords.setKeyword2("");
    }
    log.info(keys[0] + ',' + keys[1]);
    return Result.success(keywords);
}
posted @   い蜗壳  阅读(65)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示